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