]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/accept.c
2 Implement the accept API.
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
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.
15 #include "SocketInternals.h"
19 Worker routine for ::Accept and ::AcceptNB
21 @param [in] s Socket file descriptor returned from ::socket.
23 @param [in] bBlocking TRUE if this is a blocking call
24 @param [in] address Address of a buffer to receive the remote network address.
26 @param [in, out] address_len Address of a buffer containing the Length in bytes
27 of the remote network address buffer. Upon return,
28 contains the length of the remote network address.
30 @return ::accept returns zero if successful and -1 when an error occurs.
31 In the case of an error, errno contains more details.
38 struct sockaddr
* address
,
39 socklen_t
* address_len
43 struct __filedes
* pDescriptor
;
44 EFI_SOCKET_PROTOCOL
* pNewSocket
;
45 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
54 // Locate the context for this socket
56 pSocketProtocol
= BslFdToSocketProtocol ( s
,
59 if ( NULL
!= pSocketProtocol
) {
61 // TODO: Update bBlocking by anding with check for NON_BLOCKING
65 // Attempt to accept a new network connection
68 Status
= pSocketProtocol
->pfnAccept ( pSocketProtocol
,
73 } while ( bBlocking
&& ( EFI_NOT_READY
== Status
));
76 // Convert the protocol to a socket
78 NewSocketFd
= BslSocketProtocolToFd ( pNewSocket
, &errno
);
79 if ( -1 == NewSocketFd
) {
83 BslSocketCloseWork ( pNewSocket
, NULL
);
88 // Return the new socket file descriptor
95 Accept a network connection.
97 The ::accept routine waits for a network connection to the socket.
98 It is able to return the remote network address to the caller if
100 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>
101 documentation is available online.
103 @param [in] s Socket file descriptor returned from ::socket.
105 @param [in] address Address of a buffer to receive the remote network address.
107 @param [in, out] address_len Address of a buffer containing the Length in bytes
108 of the remote network address buffer. Upon return,
109 contains the length of the remote network address.
111 @return ::accept returns zero if successful and -1 when an error occurs.
112 In the case of an error, errno contains more details.
118 struct sockaddr
* address
,
119 socklen_t
* address_len
123 // Wait for the accept call to complete
125 return AcceptWork ( s
, TRUE
, address
, address_len
);
130 Non blocking version of accept.
134 @param [in] s Socket file descriptor returned from ::socket.
136 @param [in] address Address of a buffer to receive the remote network address.
138 @param [in, out] address_len Address of a buffer containing the Length in bytes
139 of the remote network address buffer. Upon return,
140 contains the length of the remote network address.
142 @return This routine returns zero if successful and -1 when an error occurs.
143 In the case of an error, errno contains more details.
149 struct sockaddr
* address
,
150 socklen_t
* address_len
154 // Attempt to accept a network connection
156 return AcceptWork ( s
, FALSE
, address
, address_len
);