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