]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the listen API.\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include <SocketInternals.h>\r | |
16 | \r | |
17 | \r | |
18 | /**\r | |
19 | Establish the known port to listen for network connections.\r | |
20 | \r | |
a88c3163 | 21 | The listen routine places the port into a state that enables connection\r |
d7ce7006 | 22 | attempts. Connections are placed into FIFO order in a queue to be serviced\r |
23 | by the application. The application calls the ::accept routine to remove\r | |
a88c3163 | 24 | the next connection from the queue and get the associated socket.\r |
25 | \r | |
26 | The\r | |
d7ce7006 | 27 | <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>\r |
a88c3163 | 28 | documentation is available online.\r |
d7ce7006 | 29 | \r |
30 | @param [in] s Socket file descriptor returned from ::socket.\r | |
31 | \r | |
32 | @param [in] backlog backlog specifies the maximum FIFO depth for the connections\r | |
a88c3163 | 33 | waiting for the application to call ::accept. Connection attempts\r |
d7ce7006 | 34 | received while the queue is full are refused.\r |
35 | \r | |
a88c3163 | 36 | @return This routine returns zero (0) if successful or -1 when an error occurs.\r |
37 | In the case of an error, ::errno contains more details.\r | |
d7ce7006 | 38 | \r |
39 | **/\r | |
40 | int\r | |
41 | listen (\r | |
42 | IN int s,\r | |
43 | IN int backlog\r | |
44 | )\r | |
45 | {\r | |
46 | int ListenStatus;\r | |
47 | EFI_SOCKET_PROTOCOL * pSocketProtocol;\r | |
48 | EFI_STATUS Status;\r | |
49 | \r | |
50 | //\r | |
51 | // Locate the context for this socket\r | |
52 | //\r | |
53 | pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );\r | |
54 | if ( NULL != pSocketProtocol ) {\r | |
55 | //\r | |
56 | // Enable connections on the known port\r | |
57 | //\r | |
58 | Status = pSocketProtocol->pfnListen ( pSocketProtocol,\r | |
59 | backlog,\r | |
60 | &errno );\r | |
61 | }\r | |
62 | \r | |
63 | //\r | |
64 | // Return the operation stauts\r | |
65 | //\r | |
66 | ListenStatus = ( 0 == errno ) ? 0 : -1;\r | |
67 | return ListenStatus;\r | |
68 | }\r |