]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/listen.c
Fix a bug about the iSCSI DHCP dependency issue.
[mirror_edk2.git] / StdLib / BsdSocketLib / listen.c
1 /** @file
2 Implement the listen API.
3
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. 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 **/
14
15 #include <SocketInternals.h>
16
17
18 /**
19 Establish the known port to listen for network connections.
20
21 The listen routine places the port into a state that enables connection
22 attempts. Connections are placed into FIFO order in a queue to be serviced
23 by the application. The application calls the ::accept routine to remove
24 the next connection from the queue and get the associated socket.
25
26 The
27 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
28 documentation is available online.
29
30 @param [in] s Socket file descriptor returned from ::socket.
31
32 @param [in] backlog backlog specifies the maximum FIFO depth for the connections
33 waiting for the application to call ::accept. Connection attempts
34 received while the queue is full are refused.
35
36 @return This routine returns zero (0) if successful or -1 when an error occurs.
37 In the case of an error, ::errno contains more details.
38
39 **/
40 int
41 listen (
42 IN int s,
43 IN int backlog
44 )
45 {
46 int ListenStatus;
47 EFI_SOCKET_PROTOCOL * pSocketProtocol;
48 EFI_STATUS Status;
49
50 //
51 // Locate the context for this socket
52 //
53 pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
54 if ( NULL != pSocketProtocol ) {
55 //
56 // Enable connections on the known port
57 //
58 Status = pSocketProtocol->pfnListen ( pSocketProtocol,
59 backlog,
60 &errno );
61 }
62
63 //
64 // Return the operation stauts
65 //
66 ListenStatus = ( 0 == errno ) ? 0 : -1;
67 return ListenStatus;
68 }