Revision: 18783
          http://sourceforge.net/p/edk2/code/18783
Author:   luobozhang
Date:     2015-11-13 09:35:54 +0000 (Fri, 13 Nov 2015)
Log Message:
-----------
NetworkPkg: Httpboot will fail the 2nd time result by wrong TCP state.

If the 2nd boot quickly after the first succeed boot, it will function well.
But if you wait for some time after 1nd succeed boot and boot again, the 
TCP state may change from established to closed wait as the http server send 
fin flag, then boot fail occurred.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <[email protected]>
Reviewed-by: Ye Ting <[email protected]>
Reviewed-by: Fu Siyuan <[email protected]>

Modified Paths:
--------------
    trunk/edk2/NetworkPkg/HttpDxe/HttpImpl.c
    trunk/edk2/NetworkPkg/HttpDxe/HttpProto.c
    trunk/edk2/NetworkPkg/HttpDxe/HttpProto.h

Modified: trunk/edk2/NetworkPkg/HttpDxe/HttpImpl.c
===================================================================
--- trunk/edk2/NetworkPkg/HttpDxe/HttpImpl.c    2015-11-13 03:27:54 UTC (rev 
18782)
+++ trunk/edk2/NetworkPkg/HttpDxe/HttpImpl.c    2015-11-13 09:35:54 UTC (rev 
18783)
@@ -317,7 +317,11 @@
   if (EFI_ERROR (Status)) {
     RemotePort = HTTP_DEFAULT_PORT;
   }
-
+  //
+  // If Configure is TRUE, it indicates the first time to call Request();
+  // If ReConfigure is TRUE, it indicates the request URL is not same
+  // with the previous call to Request();
+  //
   Configure   = TRUE;
   ReConfigure = TRUE;  
 
@@ -427,7 +431,11 @@
     //
     // The request URL is different from previous calls to Request(), close 
existing TCP instance.
     //
-    ASSERT (HttpInstance->Tcp4 != NULL &&HttpInstance->Tcp6 != NULL);
+    if (!HttpInstance->LocalAddressIsIPv6) {
+      ASSERT (HttpInstance->Tcp4 != NULL);
+    } else {
+      ASSERT (HttpInstance->Tcp6 != NULL);
+    }
     HttpCloseConnection (HttpInstance);
     EfiHttpCancel (This, NULL);
   }
@@ -445,13 +453,12 @@
   Wrap->HttpInstance   = HttpInstance;
   Wrap->TcpWrap.Method = Request->Method;
 
-  if (Configure) {
-    Status = HttpInitTcp (HttpInstance, Wrap);
-    if (EFI_ERROR (Status)) {
-      goto Error2;
-    }
+  Status = HttpInitTcp (HttpInstance, Wrap, Configure);
+  if (EFI_ERROR (Status)) {
+    goto Error2;
+  }  
 
-  } else {
+  if (!Configure) {
     //
     // For the new HTTP token, create TX TCP token events.    
     //
@@ -460,7 +467,7 @@
       goto Error1;
     }
   }
-
+  
   //
   // Create request message.
   //

Modified: trunk/edk2/NetworkPkg/HttpDxe/HttpProto.c
===================================================================
--- trunk/edk2/NetworkPkg/HttpDxe/HttpProto.c   2015-11-13 03:27:54 UTC (rev 
18782)
+++ trunk/edk2/NetworkPkg/HttpDxe/HttpProto.c   2015-11-13 09:35:54 UTC (rev 
18783)
@@ -1179,7 +1179,7 @@
   EFI_TCP4_CONNECTION_STATE Tcp4State;
 
 
-  if (HttpInstance->State != HTTP_STATE_TCP_CONFIGED || HttpInstance->Tcp4 == 
NULL) {
+  if (HttpInstance->State < HTTP_STATE_TCP_CONFIGED || HttpInstance->Tcp4 == 
NULL) {
     return EFI_NOT_READY;
   }
 
@@ -1196,9 +1196,11 @@
     return Status;
   }
 
-  if (Tcp4State > Tcp4StateEstablished) {
+  if (Tcp4State == Tcp4StateEstablished) {
+    return EFI_SUCCESS;
+  } else if (Tcp4State > Tcp4StateEstablished ) {
     HttpCloseConnection(HttpInstance);
-  }  
+  }
 
   return HttpCreateConnection (HttpInstance);
 }
@@ -1221,7 +1223,7 @@
   EFI_STATUS                Status;
   EFI_TCP6_CONNECTION_STATE Tcp6State;
 
-  if (HttpInstance->State != HTTP_STATE_TCP_CONFIGED || HttpInstance->Tcp6 == 
NULL) {
+  if (HttpInstance->State < HTTP_STATE_TCP_CONFIGED || HttpInstance->Tcp6 == 
NULL) {
     return EFI_NOT_READY;
   }
 
@@ -1239,8 +1241,10 @@
      return Status;
   }
 
-  if (Tcp6State > Tcp6StateEstablished) {
-    HttpCloseConnection (HttpInstance);
+  if (Tcp6State == Tcp6StateEstablished) {
+    return EFI_SUCCESS;
+  } else if (Tcp6State > Tcp6StateEstablished ) {
+    HttpCloseConnection(HttpInstance);
   }
 
   return HttpCreateConnection (HttpInstance);
@@ -1251,6 +1255,7 @@
 
   @param[in]  HttpInstance       The HTTP instance private data.
   @param[in]  Wrap               The HTTP token's wrap data.
+  @param[in]  Configure          The Flag indicates whether the first time to 
initialize Tcp.
 
   @retval EFI_SUCCESS            The initialization of TCP instance is done. 
   @retval Others                 Other error as indicated.
@@ -1259,7 +1264,8 @@
 EFI_STATUS
 HttpInitTcp (
   IN  HTTP_PROTOCOL    *HttpInstance,
-  IN  HTTP_TOKEN_WRAP  *Wrap
+  IN  HTTP_TOKEN_WRAP  *Wrap,
+  IN  BOOLEAN          Configure
   )
 {
   EFI_STATUS           Status;
@@ -1269,10 +1275,13 @@
     //
     // Configure TCP instance.
     //
-    Status = HttpConfigureTcp4 (HttpInstance, Wrap);
-    if (EFI_ERROR (Status)) {
-      return Status;
+    if (Configure) {
+      Status = HttpConfigureTcp4 (HttpInstance, Wrap);
+      if (EFI_ERROR (Status)) {
+        return Status;
+      }
     }
+
     //
     // Connect TCP.
     //
@@ -1284,10 +1293,13 @@
     //
     // Configure TCP instance.
     //
-    Status = HttpConfigureTcp6 (HttpInstance, Wrap);
-    if (EFI_ERROR (Status)) {
-      return Status;
+    if (Configure) {
+      Status = HttpConfigureTcp6 (HttpInstance, Wrap);
+      if (EFI_ERROR (Status)) {
+        return Status;
+      }
     }
+
     //
     // Connect TCP.
     //

Modified: trunk/edk2/NetworkPkg/HttpDxe/HttpProto.h
===================================================================
--- trunk/edk2/NetworkPkg/HttpDxe/HttpProto.h   2015-11-13 03:27:54 UTC (rev 
18782)
+++ trunk/edk2/NetworkPkg/HttpDxe/HttpProto.h   2015-11-13 09:35:54 UTC (rev 
18783)
@@ -456,6 +456,7 @@
 
   @param[in]  HttpInstance       The HTTP instance private data.
   @param[in]  Wrap               The HTTP token's wrap data.
+  @param[in]  Configure          The Flag indicates whether the first time to 
initialize Tcp.
 
   @retval EFI_SUCCESS            The initialization of TCP instance is done. 
   @retval Others                 Other error as indicated.
@@ -464,7 +465,8 @@
 EFI_STATUS
 HttpInitTcp (
   IN  HTTP_PROTOCOL    *HttpInstance,
-  IN  HTTP_TOKEN_WRAP  *Wrap
+  IN  HTTP_TOKEN_WRAP  *Wrap,
+  IN  BOOLEAN          Configure
   );
 
 /**


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to