]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/accept.c
Update the sockets library code
[mirror_edk2.git] / StdLib / BsdSocketLib / accept.c
index 25ae1b5861eef04934ff48ca4decee00ad4b883f..4f0dbac5f923081110a61200b896652008276f26 100644 (file)
 \r
 \r
 /**\r
-  Worker routine for ::Accept and ::AcceptNB\r
+  Worker routine for ::accept and ::AcceptNB\r
 \r
-  @param [in] s         Socket file descriptor returned from ::socket.\r
+  @param [in] s                 Socket file descriptor returned from ::socket.\r
 \r
-  @param [in] bBlocking TRUE if this is a blocking call\r
-  @param [in] address   Address of a buffer to receive the remote network address.\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     ::accept returns zero if successful and -1 when an error occurs.\r
-              In the case of an error, errno contains more details.\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 bBlocking,\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
@@ -58,8 +59,10 @@ AcceptWork (
                                             &errno );\r
   if ( NULL != pSocketProtocol ) {\r
     //\r
-    // TODO: Update bBlocking by anding with check for NON_BLOCKING\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
@@ -75,12 +78,14 @@ AcceptWork (
     //\r
     //  Convert the protocol to a socket\r
     //\r
-    NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );\r
-    if ( -1 == NewSocketFd ) {\r
-      //\r
-      //  Close the socket\r
-      //\r
-      BslSocketCloseWork ( pNewSocket, NULL );\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
@@ -94,9 +99,10 @@ AcceptWork (
 /**\r
   Accept a network connection.\r
 \r
-  The ::accept routine waits for a network connection to the socket.\r
-  It is able to return the remote network address to the caller if\r
-  requested.  The\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
@@ -108,8 +114,8 @@ AcceptWork (
                                 of the remote network address buffer.  Upon return,\r
                                 contains the length of the remote network address.\r
 \r
-  @return     ::accept returns zero if successful and -1 when an error occurs.\r
-              In the case of an error, errno contains more details.\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
@@ -127,9 +133,7 @@ accept (
 \r
 \r
 /**\r
-  Non blocking version of accept.\r
-\r
-  See ::accept\r
+  Non blocking version of ::accept.\r
 \r
   @param [in] s         Socket file descriptor returned from ::socket.\r
 \r
@@ -140,7 +144,7 @@ accept (
                                 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
+              In the case of an error, ::errno contains more details.\r
 \r
  **/\r
 int\r