]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/sendto.c
Update the sockets library code
[mirror_edk2.git] / StdLib / BsdSocketLib / sendto.c
index 5311ce6022155cff8d8045c6a669adf0eaa3f2f9..2fb7737c30b6167efc63418d538e3e6b34d63996 100644 (file)
 /**\r
   Send data using a network connection.\r
 \r
-  The ::send routine queues data to the network for transmission.\r
+  The sendto routine queues data to the network for transmission.\r
+  This routine is typically used for SOCK_DGRAM sockets that are shared\r
+  between multiple machine where it is required to specify the target\r
+  system address when sending the data.\r
+\r
   The\r
   <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>\r
   documentation is available online.\r
@@ -35,9 +39,9 @@
 \r
   @param [in] tolen     Length of remote system address structure\r
 \r
-  @return     ::send returns the number of data bytes that were\r
+  @return     This routine returns the number of data bytes that were\r
               sent and -1 when an error occurs.  In the case of\r
-              an error, errno contains more details.\r
+              an error, ::errno contains more details.\r
 \r
  **/\r
 ssize_t\r
@@ -50,6 +54,7 @@ sendto (
   socklen_t tolen\r
   )\r
 {\r
+  BOOLEAN bBlocking;\r
   ssize_t LengthInBytes;\r
   CONST UINT8 * pData;\r
   struct __filedes * pDescriptor;\r
@@ -68,20 +73,25 @@ sendto (
                                             &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
+\r
     //\r
     //  Send the data using the socket\r
     //\r
     pData = buffer;\r
     do {\r
       errno = 0;\r
-      Status = pSocketProtocol->pfnSend ( pSocketProtocol,\r
-                                          flags,\r
-                                          length,\r
-                                          pData,\r
-                                          (size_t *)&LengthInBytes,\r
-                                          to,\r
-                                          tolen,\r
-                                          &errno );\r
+      Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,\r
+                                              flags,\r
+                                              length,\r
+                                              pData,\r
+                                              (size_t *)&LengthInBytes,\r
+                                              to,\r
+                                              tolen,\r
+                                              &errno );\r
       if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {\r
         LengthInBytes = -1;\r
         break;\r
@@ -92,8 +102,7 @@ sendto (
       //\r
       pData += LengthInBytes;\r
       length -= LengthInBytes;\r
-      // TODO: Add non-blocking check\r
-    } while (( 0 != length ) && ( EFI_NOT_READY == Status ));\r
+    } while (( 0 != length ) && ( EFI_NOT_READY == Status ) && bBlocking );\r
   }\r
 \r
   //\r