+++ /dev/null
-/** @file\r
- Implement the accept API.\r
-\r
- Copyright (c) 2011, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#include "SocketInternals.h"\r
-\r
-\r
-/**\r
- Worker routine for ::accept and ::AcceptNB\r
-\r
- @param [in] s Socket file descriptor returned from ::socket.\r
-\r
- @param [in] bBlockingAllowed TRUE if this is a blocking call\r
- @param [in] address Address of a buffer to receive the remote network address.\r
-\r
- @param [in, out] address_len Address of a buffer containing the Length in bytes\r
- of the remote network address buffer. Upon return,\r
- contains the length of the remote network address.\r
-\r
- @return AcceptWork returns zero if successful and -1 when an error occurs.\r
- In the case of an error, ::errno contains more details.\r
-\r
- **/\r
-int\r
-AcceptWork (\r
- int s,\r
- BOOLEAN bBlockingAllowed,\r
- struct sockaddr * address,\r
- socklen_t * address_len\r
- )\r
-{\r
- BOOLEAN bBlocking;\r
- INT32 NewSocketFd;\r
- struct __filedes * pDescriptor;\r
- EFI_SOCKET_PROTOCOL * pNewSocket;\r
- EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Assume failure\r
- //\r
- NewSocketFd = -1;\r
-\r
- //\r
- // Locate the context for this socket\r
- //\r
- pSocketProtocol = BslFdToSocketProtocol ( s,\r
- &pDescriptor,\r
- &errno );\r
- if ( NULL != pSocketProtocol ) {\r
- //\r
- // Determine if the operation is blocking\r
- //\r
- bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));\r
- bBlocking &= bBlockingAllowed;\r
-\r
- //\r
- // Attempt to accept a new network connection\r
- //\r
- do {\r
- Status = pSocketProtocol->pfnAccept ( pSocketProtocol,\r
- address,\r
- address_len,\r
- &pNewSocket,\r
- &errno );\r
- } while ( bBlocking && ( EFI_NOT_READY == Status ));\r
-\r
- //\r
- // Convert the protocol to a socket\r
- //\r
- if ( !EFI_ERROR ( Status )) {\r
- NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );\r
- if ( -1 == NewSocketFd ) {\r
- //\r
- // Close the socket\r
- //\r
- BslSocketCloseWork ( pNewSocket, NULL );\r
- }\r
- }\r
- }\r
-\r
- //\r
- // Return the new socket file descriptor\r
- //\r
- return NewSocketFd;\r
-}\r
-\r
-\r
-/**\r
- Accept a network connection.\r
-\r
- The accept routine waits for a network connection to the socket.\r
- It returns the remote network address to the caller if requested.\r
-\r
- The\r
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>\r
- documentation is available online.\r
-\r
- @param [in] s Socket file descriptor returned from ::socket.\r
-\r
- @param [in] address Address of a buffer to receive the remote network address.\r
-\r
- @param [in, out] address_len Address of a buffer containing the Length in bytes\r
- of the remote network address buffer. Upon return,\r
- contains the length of the remote network address.\r
-\r
- @return The accept routine returns zero if successful and -1 when an error occurs.\r
- In the case of an error, ::errno contains more details.\r
-\r
- **/\r
-int\r
-accept (\r
- int s,\r
- struct sockaddr * address,\r
- socklen_t * address_len\r
- )\r
-{\r
- //\r
- // Wait for the accept call to complete\r
- //\r
- return AcceptWork ( s, TRUE, address, address_len );\r
-}\r
-\r
-\r
-/**\r
- Non blocking version of ::accept.\r
-\r
- @param [in] s Socket file descriptor returned from ::socket.\r
-\r
- @param [in] address Address of a buffer to receive the remote network address.\r
-\r
- @param [in, out] address_len Address of a buffer containing the Length in bytes\r
- of the remote network address buffer. Upon return,\r
- contains the length of the remote network address.\r
-\r
- @return This routine returns zero if successful and -1 when an error occurs.\r
- In the case of an error, ::errno contains more details.\r
-\r
- **/\r
-int\r
-AcceptNB (\r
- int s,\r
- struct sockaddr * address,\r
- socklen_t * address_len\r
- )\r
-{\r
- //\r
- // Attempt to accept a network connection\r
- //\r
- return AcceptWork ( s, FALSE, address, address_len );\r
-}\r