]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg: HttpDxe response/cancel issue fix
[mirror_edk2.git] / NetworkPkg / HttpDxe / HttpImpl.c
index 12f22dbbb14be991df57da3d16cce03a64d5d260..ad194dbe0e5556da82d703477302082d690ff3c6 100644 (file)
@@ -462,7 +462,6 @@ EfiHttpRequest (
       }\r
     }\r
 \r
-\r
     //\r
     // Save the RemotePort and RemoteHost.\r
     //\r
@@ -578,13 +577,13 @@ EfiHttpRequest (
   return EFI_SUCCESS;\r
 \r
 Error5:\r
-    //\r
-    // We would have inserted a TxToken only if Request structure is not NULL.\r
-    // Hence check before we do a remove in this error case.\r
-    //\r
-    if (Request != NULL) {\r
-      NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
-    }\r
+  //\r
+  // We would have inserted a TxToken only if Request structure is not NULL.\r
+  // Hence check before we do a remove in this error case.\r
+  //\r
+  if (Request != NULL) {\r
+    NetMapRemoveTail (&HttpInstance->TxTokens, NULL);\r
+  }\r
 \r
 Error4:\r
   if (RequestMsg != NULL) {\r
@@ -606,7 +605,6 @@ Error2:
   }\r
 \r
 Error1:\r
-\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -640,7 +638,6 @@ HttpCancelTokens (
   IN VOID                   *Context\r
   )\r
 {\r
-\r
   EFI_HTTP_TOKEN            *Token;\r
   HTTP_TOKEN_WRAP           *Wrap;\r
   HTTP_PROTOCOL             *HttpInstance;\r
@@ -658,42 +655,33 @@ HttpCancelTokens (
   Wrap = (HTTP_TOKEN_WRAP *) Item->Value;\r
   ASSERT (Wrap != NULL);\r
   HttpInstance = Wrap->HttpInstance;\r
-\r
-  //\r
-  // Free resources.\r
-  //\r
-  NetMapRemoveItem (Map, Item, NULL); \r
   \r
   if (!HttpInstance->LocalAddressIsIPv6) {\r
-    if (Wrap->TcpWrap.Tx4Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Tx4Token.CompletionToken.Event);\r
-    }\r
-    \r
     if (Wrap->TcpWrap.Rx4Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Rx4Token.CompletionToken.Event);\r
-    }\r
-    \r
-    if (Wrap->TcpWrap.Rx4Token.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {\r
-      FreePool (Wrap->TcpWrap.Rx4Token.Packet.RxData->FragmentTable[0].FragmentBuffer);\r
-    }\r
+      //\r
+      // Cancle the Token before close its Event.\r
+      //\r
+      HttpInstance->Tcp4->Cancel (HttpInstance->Tcp4, &Wrap->TcpWrap.Rx4Token.CompletionToken);\r
 \r
-  } else {\r
-    if (Wrap->TcpWrap.Tx6Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Tx6Token.CompletionToken.Event);\r
+      //\r
+      // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
+      //\r
+      DispatchDpc ();\r
     }\r
-\r
+  } else {\r
     if (Wrap->TcpWrap.Rx6Token.CompletionToken.Event != NULL) {\r
-      gBS->CloseEvent (Wrap->TcpWrap.Rx6Token.CompletionToken.Event);\r
-    }\r
+      //\r
+      // Cancle the Token before close its Event.\r
+      //\r
+      HttpInstance->Tcp6->Cancel (HttpInstance->Tcp6, &Wrap->TcpWrap.Rx6Token.CompletionToken);\r
 \r
-    if (Wrap->TcpWrap.Rx6Token.Packet.RxData->FragmentTable[0].FragmentBuffer != NULL) {\r
-      FreePool (Wrap->TcpWrap.Rx6Token.Packet.RxData->FragmentTable[0].FragmentBuffer);\r
+      //\r
+      // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.\r
+      //\r
+      DispatchDpc ();\r
     }\r
   }\r
 \r
-\r
-  FreePool (Wrap);\r
-\r
   //\r
   // If only one item is to be cancel, return EFI_ABORTED to stop\r
   // iterating the map any more.\r
@@ -1009,6 +997,7 @@ HttpResponseWorker (
     //\r
     StatusCodeStr = HttpHeaders + AsciiStrLen (HTTP_VERSION_STR) + 1;\r
     if (StatusCodeStr == NULL) {\r
+      Status = EFI_NOT_READY;\r
       goto Error;\r
     }\r
 \r
@@ -1019,6 +1008,7 @@ HttpResponseWorker (
     //\r
     Tmp = AsciiStrStr (HttpHeaders, HTTP_CRLF_STR);\r
     if (Tmp == NULL) {\r
+      Status = EFI_NOT_READY;\r
       goto Error;\r
     }\r
 \r
@@ -1065,6 +1055,7 @@ HttpResponseWorker (
     if (SizeofHeaders != 0) {\r
       HeaderTmp = AllocateZeroPool (SizeofHeaders);\r
       if (HeaderTmp == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         goto Error2;\r
       }\r
 \r
@@ -1204,42 +1195,14 @@ HttpResponseWorker (
 \r
   ASSERT (HttpInstance->MsgParser != NULL);\r
 \r
-  if (HttpInstance->TimeoutEvent == NULL) {\r
-    //\r
-    // Create TimeoutEvent for response\r
-    //\r
-    Status = gBS->CreateEvent (\r
-                    EVT_TIMER,\r
-                    TPL_CALLBACK,\r
-                    NULL,\r
-                    NULL,\r
-                    &HttpInstance->TimeoutEvent\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
-      goto Error2;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Start the timer, and wait Timeout seconds to receive the body packet.\r
-  //\r
-  Status = gBS->SetTimer (HttpInstance->TimeoutEvent, TimerRelative, HTTP_RESPONSE_TIMEOUT * TICKS_PER_SECOND);\r
-  if (EFI_ERROR (Status)) {\r
-    goto Error2;\r
-  }\r
-\r
   //\r
   // We still need receive more data when there is no cache data and MsgParser is not NULL;\r
   //\r
-  Status = HttpTcpReceiveBody (Wrap, HttpMsg, HttpInstance->TimeoutEvent);\r
-\r
-  gBS->SetTimer (HttpInstance->TimeoutEvent, TimerCancel, 0);\r
-\r
+  Status = HttpTcpReceiveBody (Wrap, HttpMsg);\r
   if (EFI_ERROR (Status)) {\r
     goto Error2;\r
   }\r
 \r
-  FreePool (Wrap);\r
   return Status;\r
 \r
 Exit:\r
@@ -1265,6 +1228,11 @@ Error2:
   }\r
 \r
 Error:\r
+  Item = NetMapFindKey (&Wrap->HttpInstance->RxTokens, Wrap->HttpToken);\r
+  if (Item != NULL) {\r
+    NetMapRemoveItem (&Wrap->HttpInstance->RxTokens, Item, NULL);\r
+  }\r
+  \r
   HttpTcpTokenCleanup (Wrap);\r
   \r
   if (HttpHeaders != NULL) {\r