]>
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] bBlockingAllowed 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 AcceptWork returns zero if successful and -1 when an error occurs.
31 In the case of an error, ::errno contains more details.
37 BOOLEAN bBlockingAllowed
,
38 struct sockaddr
* address
,
39 socklen_t
* address_len
44 struct __filedes
* pDescriptor
;
45 EFI_SOCKET_PROTOCOL
* pNewSocket
;
46 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
55 // Locate the context for this socket
57 pSocketProtocol
= BslFdToSocketProtocol ( s
,
60 if ( NULL
!= pSocketProtocol
) {
62 // Determine if the operation is blocking
64 bBlocking
= (BOOLEAN
)( 0 == ( pDescriptor
->Oflags
& O_NONBLOCK
));
65 bBlocking
&= bBlockingAllowed
;
68 // Attempt to accept a new network connection
71 Status
= pSocketProtocol
->pfnAccept ( pSocketProtocol
,
76 } while ( bBlocking
&& ( EFI_NOT_READY
== Status
));
79 // Convert the protocol to a socket
81 if ( !EFI_ERROR ( Status
)) {
82 NewSocketFd
= BslSocketProtocolToFd ( pNewSocket
, &errno
);
83 if ( -1 == NewSocketFd
) {
87 BslSocketCloseWork ( pNewSocket
, NULL
);
93 // Return the new socket file descriptor
100 Accept a network connection.
102 The accept routine waits for a network connection to the socket.
103 It returns the remote network address to the caller if requested.
106 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>
107 documentation is available online.
109 @param [in] s Socket file descriptor returned from ::socket.
111 @param [in] address Address of a buffer to receive the remote network address.
113 @param [in, out] address_len Address of a buffer containing the Length in bytes
114 of the remote network address buffer. Upon return,
115 contains the length of the remote network address.
117 @return The accept routine returns zero if successful and -1 when an error occurs.
118 In the case of an error, ::errno contains more details.
124 struct sockaddr
* address
,
125 socklen_t
* address_len
129 // Wait for the accept call to complete
131 return AcceptWork ( s
, TRUE
, address
, address_len
);
136 Non blocking version of ::accept.
138 @param [in] s Socket file descriptor returned from ::socket.
140 @param [in] address Address of a buffer to receive the remote network address.
142 @param [in, out] address_len Address of a buffer containing the Length in bytes
143 of the remote network address buffer. Upon return,
144 contains the length of the remote network address.
146 @return This routine returns zero if successful and -1 when an error occurs.
147 In the case of an error, ::errno contains more details.
153 struct sockaddr
* address
,
154 socklen_t
* address_len
158 // Attempt to accept a network connection
160 return AcceptWork ( s
, FALSE
, address
, address_len
);