summaryrefslogtreecommitdiff
path: root/NetworkPkg
diff options
context:
space:
mode:
authorFu Siyuan <siyuan.fu@intel.com>2015-09-14 09:05:49 +0000
committersfu5 <sfu5@Edk2>2015-09-14 09:05:49 +0000
commit51b0450e002431b7cb902220c513ddaf589f3600 (patch)
treef83f2c99849cc47178b8e039ecd73d501ac55c74 /NetworkPkg
parent7fd71047a6d355408b5eb7238c880a75c1a247d9 (diff)
NetworkPkg: Avoid memory allocation for each HTTP message exchange.
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
Diffstat (limited to 'NetworkPkg')
-rw-r--r--NetworkPkg/HttpDxe/HttpImpl.c19
-rw-r--r--NetworkPkg/HttpDxe/HttpProto.c11
-rw-r--r--NetworkPkg/HttpDxe/HttpProto.h4
3 files changed, 25 insertions, 9 deletions
diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c
index dc06b9855..c5b2be430 100644
--- a/NetworkPkg/HttpDxe/HttpImpl.c
+++ b/NetworkPkg/HttpDxe/HttpImpl.c
@@ -224,6 +224,7 @@ EfiHttpRequest (
BOOLEAN ReConfigure;
CHAR8 *RequestStr;
CHAR8 *Url;
+ UINTN UrlLen;
CHAR16 *HostNameStr;
HTTP_TOKEN_WRAP *Wrap;
HTTP_TCP_TOKEN_WRAP *TcpWrap;
@@ -283,10 +284,15 @@ EfiHttpRequest (
//
// Parse the URI of the remote host.
//
- Url = AllocatePool (StrLen (Request->Url) + 1);
- if (Url == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
+ UrlLen = StrLen (Request->Url) + 1;
+ if (UrlLen > HTTP_URL_BUFFER_LEN) {
+ Url = AllocateZeroPool (UrlLen);
+ if (Url == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ FreePool (HttpInstance->Url);
+ HttpInstance->Url = Url;
+ }
UnicodeStrToAsciiStr (Request->Url, Url);
UrlParser = NULL;
@@ -347,7 +353,6 @@ EfiHttpRequest (
Wrap->TcpWrap.Method = Request->Method;
- FreePool (Url);
FreePool (HostName);
//
@@ -480,7 +485,6 @@ EfiHttpRequest (
goto Error4;
}
- FreePool (Url);
if (HostName != NULL) {
FreePool (HostName);
}
@@ -520,9 +524,6 @@ Error2:
}
Error1:
- if (Url != NULL) {
- FreePool (Url);
- }
if (HostName != NULL) {
FreePool (HostName);
}
diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index e8ce9879f..99f907e10 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -431,6 +431,12 @@ HttpInitProtocol (
goto ON_ERROR;
}
+ HttpInstance->Url = AllocateZeroPool (HTTP_URL_BUFFER_LEN);
+ if (HttpInstance->Url == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto ON_ERROR;
+ }
+
NetMapInit (&HttpInstance->TxTokens);
NetMapInit (&HttpInstance->RxTokens);
@@ -496,6 +502,11 @@ HttpCleanProtocol (
HttpInstance->MsgParser = NULL;
}
+ if (HttpInstance->Url != NULL) {
+ FreePool (HttpInstance->Url);
+ HttpInstance->Url = NULL;
+ }
+
NetMapClean (&HttpInstance->TxTokens);
NetMapClean (&HttpInstance->RxTokens);
diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h
index ca4b7b603..c37b80c8e 100644
--- a/NetworkPkg/HttpDxe/HttpProto.h
+++ b/NetworkPkg/HttpDxe/HttpProto.h
@@ -51,6 +51,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#define HTTP_KEEP_ALIVE_TIME 7200
#define HTTP_KEEP_ALIVE_INTERVAL 30
+#define HTTP_URL_BUFFER_LEN 4096
+
typedef struct _HTTP_SERVICE {
UINT32 Signature;
EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;
@@ -120,6 +122,8 @@ typedef struct _HTTP_PROTOCOL {
NET_MAP TxTokens;
NET_MAP RxTokens;
+
+ CHAR8 *Url;
} HTTP_PROTOCOL;
typedef struct {