]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix issues detected by python web-server.
authorlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Feb 2012 18:45:09 +0000 (18:45 +0000)
committerlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Feb 2012 18:45:09 +0000 (18:45 +0000)
* Removed display of TPL
* Added NOP implementation for SO_REUSEADDR
* Add better detection of socket address
* Return first address

Signed-off-by: lpleahy
Python Web server below:

---------------

import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler

HandlerClass = SimpleHTTPRequestHandler
ServerClass  = BaseHTTPServer.HTTPServer
Protocol     = "HTTP/1.0"

port = 80
server_address = ('', port)

HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13034 6f19259b-4bc3-4df7-8a09-765794883524

StdLib/EfiSocketLib/Ip4.c
StdLib/EfiSocketLib/Socket.c
StdLib/EfiSocketLib/Socket.h
StdLib/EfiSocketLib/Tcp4.c
StdLib/EfiSocketLib/Tcp6.c
StdLib/EfiSocketLib/Udp4.c
StdLib/EfiSocketLib/Udp6.c
StdLib/Include/Efi/EfiSocketLib.h

index f295b4250e12501523f445f2dc26e9c72fb4c822..5a0f5284f5eeb3f2e8c6b4637449930e87537cd3 100644 (file)
@@ -619,6 +619,7 @@ EslIp4RemoteAddressSet (
   pIp4->DestinationAddress.Addr[1] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 8 );\r
   pIp4->DestinationAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );\r
   pIp4->DestinationAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );\r
+  pPort->pSocket->bAddressSet = TRUE;\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
index d6adba3237219f9ecb5ca3295f199c6ddf16431d..acb23677aa6a8650c8c88910f57764ee2282555e 100644 (file)
@@ -1259,7 +1259,10 @@ EslSocketBind (
       //\r
       //  Verify that at least one network connection was found\r
       //\r
-      if ( NULL == pSocket->pPortList ) {\r
+      if ( NULL != pSocket->pPortList ) {\r
+        Status = EFI_SUCCESS;\r
+      }\r
+      else {\r
         if ( EADDRNOTAVAIL == pSocket->errno ) {\r
           DEBUG (( DEBUG_BIND | DEBUG_POOL | DEBUG_INIT,\r
                     "ERROR - Socket address is not available!\r\n" ));\r
@@ -1993,70 +1996,60 @@ EslSocketGetLocalAddress (
     //\r
     //  Verify the socket state\r
     //\r
-    Status = EslSocketIsConfigured ( pSocket );\r
-    if ( !EFI_ERROR ( Status )) {\r
+    EslSocketIsConfigured ( pSocket );\r
+    if ( pSocket->bAddressSet ) {\r
       //\r
       //  Verify the address buffer and length address\r
       //\r
       if (( NULL != pAddress ) && ( NULL != pAddressLength )) {\r
         //\r
-        //  Verify the socket state\r
+        //  Verify the API\r
         //\r
-        if (( SOCKET_STATE_CONNECTED == pSocket->State )\r
-          || ( SOCKET_STATE_LISTENING == pSocket->State )) {\r
+        if ( NULL == pSocket->pApi->pfnLocalAddrGet ) {\r
+          Status = EFI_UNSUPPORTED;\r
+          pSocket->errno = ENOTSUP;\r
+        }\r
+        else {\r
           //\r
-          //  Verify the API\r
+          //  Synchronize with the socket layer\r
           //\r
-          if ( NULL == pSocket->pApi->pfnLocalAddrGet ) {\r
-            Status = EFI_UNSUPPORTED;\r
-            pSocket->errno = ENOTSUP;\r
-          }\r
-          else {\r
-            //\r
-            //  Synchronize with the socket layer\r
-            //\r
-            RAISE_TPL ( TplPrevious, TPL_SOCKETS );\r
+          RAISE_TPL ( TplPrevious, TPL_SOCKETS );\r
 \r
+          //\r
+          //  Verify that there is just a single connection\r
+          //\r
+          pPort = pSocket->pPortList;\r
+          if ( NULL != pPort ) {\r
             //\r
-            //  Verify that there is just a single connection\r
+            //  Verify the address length\r
             //\r
-            pPort = pSocket->pPortList;\r
-            if (( NULL != pPort ) && ( NULL == pPort->pLinkSocket )) {\r
+            LengthInBytes = pSocket->pApi->AddressLength;\r
+            if (( LengthInBytes <= *pAddressLength ) \r
+              && ( 255 >= LengthInBytes )) {\r
               //\r
-              //  Verify the address length\r
+              //  Return the local address and address length\r
               //\r
-              LengthInBytes = pSocket->pApi->AddressLength;\r
-              if (( LengthInBytes <= *pAddressLength ) \r
-                && ( 255 >= LengthInBytes )) {\r
-                //\r
-                //  Return the local address and address length\r
-                //\r
-                ZeroMem ( pAddress, LengthInBytes );\r
-                pAddress->sa_len = (uint8_t)LengthInBytes;\r
-                *pAddressLength = pAddress->sa_len;\r
-                pSocket->pApi->pfnLocalAddrGet ( pPort, pAddress );\r
-                pSocket->errno = 0;\r
-                Status = EFI_SUCCESS;\r
-              }\r
-              else {\r
-                pSocket->errno = EINVAL;\r
-                Status = EFI_INVALID_PARAMETER;\r
-              }\r
+              ZeroMem ( pAddress, LengthInBytes );\r
+              pAddress->sa_len = (uint8_t)LengthInBytes;\r
+              *pAddressLength = pAddress->sa_len;\r
+              pSocket->pApi->pfnLocalAddrGet ( pPort, pAddress );\r
+              pSocket->errno = 0;\r
+              Status = EFI_SUCCESS;\r
             }\r
             else {\r
-              pSocket->errno = ENOTCONN;\r
-              Status = EFI_NOT_STARTED;\r
+              pSocket->errno = EINVAL;\r
+              Status = EFI_INVALID_PARAMETER;\r
             }\r
-            \r
-            //\r
-            //  Release the socket layer synchronization\r
-            //\r
-            RESTORE_TPL ( TplPrevious );\r
           }\r
-        }\r
-        else {\r
-          pSocket->errno = ENOTCONN;\r
-          Status = EFI_NOT_STARTED;\r
+          else {\r
+            pSocket->errno = ENOTCONN;\r
+            Status = EFI_NOT_STARTED;\r
+          }\r
+          \r
+          //\r
+          //  Release the socket layer synchronization\r
+          //\r
+          RESTORE_TPL ( TplPrevious );\r
         }\r
       }\r
       else {\r
@@ -2064,6 +2057,13 @@ EslSocketGetLocalAddress (
         Status = EFI_INVALID_PARAMETER;\r
       }\r
     }\r
+    else {\r
+      //\r
+      //  Address not set\r
+      //\r
+      Status = EFI_NOT_STARTED;\r
+      pSocket->errno = EADDRNOTAVAIL;\r
+    }\r
   }\r
   \r
   //\r
@@ -2808,6 +2808,14 @@ EslSocketOptionGet (
         LengthInBytes = sizeof ( pSocket->MaxRxBuf );\r
         break;\r
 \r
+      case SO_REUSEADDR:\r
+        //\r
+        //  Return the address reuse flag\r
+        //\r
+        pOptionData = (UINT8 *)&pSocket->bReUseAddr;\r
+        LengthInBytes = sizeof ( pSocket->bReUseAddr );\r
+        break;\r
+      \r
       case SO_SNDBUF:\r
         //\r
         //  Return the maximum transmit buffer size\r
@@ -3032,6 +3040,14 @@ EslSocketOptionSet (
           LengthInBytes = sizeof ( pSocket->MaxRxBuf );\r
           break;\r
 \r
+        case SO_REUSEADDR:\r
+          //\r
+          //  Return the address reuse flag\r
+          //\r
+          pOptionData = (UINT8 *)&pSocket->bReUseAddr;\r
+          LengthInBytes = sizeof ( pSocket->bReUseAddr );\r
+          break;\r
+\r
         case SO_SNDBUF:\r
           //\r
           //  Send buffer size\r
index 30b642000e6e6b9d1bad9301785aad37f34c83c6..f2fbdb57b374043c5c25163a3b24008bacc046cc 100644 (file)
@@ -989,9 +989,10 @@ typedef struct _ESL_SOCKET {
   //\r
   //  Socket options\r
   //\r
+  BOOLEAN bIncludeHeader;       ///<  TRUE if including the IP header\r
   BOOLEAN bListenCalled;        ///<  TRUE if listen was successfully called\r
   BOOLEAN bOobInLine;           ///<  TRUE if out-of-band messages are to be received inline with normal data\r
-  BOOLEAN bIncludeHeader;       ///<  TRUE if including the IP header\r
+  BOOLEAN bReUseAddr;           ///<  TRUE if using same address is allowed\r
 \r
   //\r
   //  Socket data\r
@@ -999,6 +1000,7 @@ typedef struct _ESL_SOCKET {
   int Domain;                   ///<  Specifies family of protocols\r
   int Type;                     ///<  Specifies how to make network connection\r
   int Protocol;                 ///<  Specifies lower layer protocol to use\r
+  BOOLEAN bAddressSet;          ///<  Set when the address is specified\r
   BOOLEAN bConfigured;          ///<  Set after the socket is configured\r
 \r
   BOOLEAN bRxDisable;           ///<  Receive disabled via shutdown\r
index b3ed45a716e1728636295a26baaaf736cf6d17a3..32c7a394c4a4d10497813732f2d01e0577d5db85 100644 (file)
@@ -1171,6 +1171,7 @@ EslTcp4LocalAddressSet (
       //  Set the port number\r
       //\r
       pAccessPoint->StationPort = SwapBytes16 ( pIpAddress->sin_port );\r
+      pPort->pSocket->bAddressSet = TRUE;\r
 \r
       //\r
       //  Display the local address\r
index 0ee9fb6a643ca22faee4ab24d73bc9ae96e2f96f..6f2cf757797bb5730c0d7da939c49268a2673d6c 100644 (file)
@@ -1210,6 +1210,7 @@ EslTcp6LocalAddressSet (
       //  Set the port number\r
       //\r
       pAccessPoint->StationPort = SwapBytes16 ( pIpAddress->sin6_port );\r
+      pPort->pSocket->bAddressSet = TRUE;\r
 \r
       //\r
       //  Display the local address\r
index 6625c078d0febb4a85167af6a4a6c7ee0329df26..ae67c4e8c543f8a770b3a8553cc5ce5f48a80c29 100644 (file)
@@ -463,6 +463,7 @@ EslUdp4RemoteAddressSet (
   pUdp4->ConfigData.RemoteAddress.Addr[2] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 16 );\r
   pUdp4->ConfigData.RemoteAddress.Addr[3] = (UINT8)( pRemoteAddress->sin_addr.s_addr >> 24 );\r
   pUdp4->ConfigData.RemotePort = SwapBytes16 ( pRemoteAddress->sin_port );\r
+  pPort->pSocket->bAddressSet = TRUE;\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
index 187f0ad6415ef33037537e7541da1a8efeb3baa0..9f47f1c736c2f575678ab4636048454af0129882 100644 (file)
@@ -113,6 +113,7 @@ EslUdp6LocalAddressSet (
     //  Set the port number\r
     //\r
     pConfig->StationPort = SwapBytes16 ( pIpAddress->sin6_port );\r
+    pPort->pSocket->bAddressSet = TRUE;\r
 \r
     //\r
     //  Display the local address\r
index f71653fa164efb8e254da176f8b1677fb4d6ebd7..d78e9f6a12a7cf0b55aaff3875b9d98a5374f47e 100644 (file)
 **/\r
 #define RAISE_TPL(PreviousTpl, tpl)     \\r
   VERIFY_TPL ( tpl );                   \\r
-  PreviousTpl = gBS->RaiseTPL ( tpl );  \\r
-  DEBUG (( DEBUG_TPL | DEBUG_TPL,       \\r
-          "%d: TPL\r\n",                \\r
-          tpl ))\r
+  PreviousTpl = gBS->RaiseTPL ( tpl );\r
 \r
 /**\r
   Restore the TPL to the previous value\r
 **/\r
 #define RESTORE_TPL(tpl)            \\r
-  DEBUG (( DEBUG_TPL | DEBUG_TPL,   \\r
-          "%d: TPL\r\n",            \\r
-          tpl ));                   \\r
   gBS->RestoreTPL ( tpl )\r
 \r
 //------------------------------------------------------------------------------\r