]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Avoid memory allocation for each HTTP message exchange.
authorFu Siyuan <siyuan.fu@intel.com>
Mon, 14 Sep 2015 09:05:49 +0000 (09:05 +0000)
committersfu5 <sfu5@Edk2>
Mon, 14 Sep 2015 09:05:49 +0000 (09:05 +0000)
This patch updates the HTTP driver to use a shared buffer for URL parsing to
avoid memory allocation for each HTTP request.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18449 6f19259b-4bc3-4df7-8a09-765794883524

NetworkPkg/HttpDxe/HttpImpl.c
NetworkPkg/HttpDxe/HttpProto.c
NetworkPkg/HttpDxe/HttpProto.h

index dc06b9855c279a801cffc5bf3a59638de05adc72..c5b2be430e29261f7e6eab37585347af95d3e673 100644 (file)
@@ -224,6 +224,7 @@ EfiHttpRequest (
   BOOLEAN                       ReConfigure;\r
   CHAR8                         *RequestStr;\r
   CHAR8                         *Url;\r
+  UINTN                         UrlLen;\r
   CHAR16                        *HostNameStr;\r
   HTTP_TOKEN_WRAP               *Wrap;\r
   HTTP_TCP_TOKEN_WRAP           *TcpWrap;\r
@@ -283,10 +284,15 @@ EfiHttpRequest (
   //\r
   // Parse the URI of the remote host.\r
   //\r
-  Url = AllocatePool (StrLen (Request->Url) + 1);\r
-  if (Url == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  UrlLen = StrLen (Request->Url) + 1;\r
+  if (UrlLen > HTTP_URL_BUFFER_LEN) {\r
+    Url = AllocateZeroPool (UrlLen);\r
+    if (Url == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    FreePool (HttpInstance->Url);\r
+    HttpInstance->Url = Url;    \r
+  }  \r
 \r
   UnicodeStrToAsciiStr (Request->Url, Url);\r
   UrlParser = NULL;\r
@@ -347,7 +353,6 @@ EfiHttpRequest (
 \r
         Wrap->TcpWrap.Method = Request->Method;\r
 \r
-        FreePool (Url);\r
         FreePool (HostName);\r
         \r
         //\r
@@ -480,7 +485,6 @@ EfiHttpRequest (
     goto Error4;\r
   }\r
 \r
-  FreePool (Url);\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
@@ -520,9 +524,6 @@ Error2:
   }\r
 \r
 Error1:\r
-  if (Url != NULL) {\r
-    FreePool (Url);\r
-  }\r
   if (HostName != NULL) {\r
     FreePool (HostName);\r
   }\r
index e8ce9879f309d159a35e2f5f8e2d28b2a0a52dac..99f907e10c7f96e8598d90de41e1a0b6e27c9038 100644 (file)
@@ -431,6 +431,12 @@ HttpInitProtocol (
     goto ON_ERROR;\r
   }\r
 \r
+  HttpInstance->Url = AllocateZeroPool (HTTP_URL_BUFFER_LEN);\r
+  if (HttpInstance->Url == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto ON_ERROR;\r
+  }\r
+\r
   NetMapInit (&HttpInstance->TxTokens);\r
   NetMapInit (&HttpInstance->RxTokens);\r
 \r
@@ -496,6 +502,11 @@ HttpCleanProtocol (
     HttpInstance->MsgParser = NULL;\r
   }\r
 \r
+  if (HttpInstance->Url != NULL) {\r
+    FreePool (HttpInstance->Url);\r
+    HttpInstance->Url = NULL;\r
+  }\r
+\r
   NetMapClean (&HttpInstance->TxTokens);\r
   NetMapClean (&HttpInstance->RxTokens);\r
 \r
index ca4b7b60353d24ee36cb7af70deacd3486cec3e7..c37b80c8ec745d62e5f2a34ba2c227757ed0fcbe 100644 (file)
@@ -51,6 +51,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define HTTP_KEEP_ALIVE_TIME         7200\r
 #define HTTP_KEEP_ALIVE_INTERVAL     30\r
 \r
+#define HTTP_URL_BUFFER_LEN          4096\r
+\r
 typedef struct _HTTP_SERVICE {\r
   UINT32                        Signature;\r
   EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;\r
@@ -120,6 +122,8 @@ typedef struct _HTTP_PROTOCOL {
 \r
   NET_MAP                       TxTokens;\r
   NET_MAP                       RxTokens;\r
+\r
+  CHAR8                         *Url;\r
 } HTTP_PROTOCOL;\r
 \r
 typedef struct {\r