summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
b578030)
The original HTTP boot driver always save the received message body in its cache,
it bring a large of memory allocation during HTTP download. This patch updates
the HTTP boot driver to only cache data when caller doesn't provide a buffer for
download (which is usually used when caller want to get the required buffer size).
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@18448
6f19259b-4bc3-4df7-8a09-
765794883524
}\r
\r
CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;\r
}\r
\r
CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;\r
-\r
- //\r
- // Save the data into cache list.\r
- //\r
- NewEntityData = AllocatePool (sizeof (HTTP_BOOT_ENTITY_DATA));\r
- if (NewEntityData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
- if (CallbackData->NewBlock) {\r
- NewEntityData->Block = CallbackData->Block;\r
- CallbackData->Block = NULL;\r
- }\r
- NewEntityData->DataLength = Length;\r
- NewEntityData->DataStart = (UINT8*) Data;\r
- InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link);\r
-\r
//\r
// Copy data if caller has provided a buffer.\r
//\r
//\r
// Copy data if caller has provided a buffer.\r
//\r
CallbackData->CopyedSize += MIN (Length, CallbackData->BufferSize - CallbackData->CopyedSize);\r
}\r
\r
CallbackData->CopyedSize += MIN (Length, CallbackData->BufferSize - CallbackData->CopyedSize);\r
}\r
\r
+ //\r
+ // The caller doesn't provide a buffer, save the block into cache list.\r
+ //\r
+ if (CallbackData->Cache != NULL) {\r
+ NewEntityData = AllocatePool (sizeof (HTTP_BOOT_ENTITY_DATA));\r
+ if (NewEntityData == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ if (CallbackData->NewBlock) {\r
+ NewEntityData->Block = CallbackData->Block;\r
+ CallbackData->Block = NULL;\r
+ }\r
+ NewEntityData->DataLength = Length;\r
+ NewEntityData->DataStart = (UINT8*) Data;\r
+ InsertTailList (&CallbackData->Cache->EntityDataList, &NewEntityData->Link);\r
+ }\r
return EFI_SUCCESS;\r
}\r
\r
return EFI_SUCCESS;\r
}\r
\r
- // 1. Create a temp cache item for the requested URI.\r
+ // 1. Create a temp cache item for the requested URI if caller doesn't provide buffer.\r
+ if ((!HeaderOnly) && (*BufferSize == 0)) {\r
Cache = AllocateZeroPool (sizeof (HTTP_BOOT_CACHE_CONTENT));\r
if (Cache == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
Cache = AllocateZeroPool (sizeof (HTTP_BOOT_CACHE_CONTENT));\r
if (Cache == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
//\r
// 2.3 Record the request info in a temp cache item.\r
//\r
//\r
// 2.3 Record the request info in a temp cache item.\r
//\r
Cache->RequestData = RequestData;\r
}\r
\r
Cache->RequestData = RequestData;\r
}\r
\r
//\r
// 3.2 Cache the response header.\r
//\r
//\r
// 3.2 Cache the response header.\r
//\r
Cache->ResponseData = ResponseData;\r
}\r
\r
Cache->ResponseData = ResponseData;\r
}\r
\r
//\r
// 3.4 Continue to receive and parse message-body if needed.\r
//\r
//\r
// 3.4 Continue to receive and parse message-body if needed.\r
//\r
if (!HeaderOnly) {\r
ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESOPNSE_DATA));\r
while (!HttpIsMessageComplete (Parser)) {\r
//\r
if (!HeaderOnly) {\r
ZeroMem (&ResponseBody, sizeof (HTTP_IO_RESOPNSE_DATA));\r
while (!HttpIsMessageComplete (Parser)) {\r
//\r
- // Allocate a new block to hold the message-body.\r
+ // Allocate a block to hold the message-body, if caller doesn't provide\r
+ // a buffer, the block will be cached and we will allocate a new one here.\r
- Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE);\r
- if (Block == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- goto ERROR_6;\r
+ if (Block == NULL || Context.BufferSize == 0) {\r
+ Block = AllocatePool (HTTP_BOOT_BLOCK_SIZE);\r
+ if (Block == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto ERROR_6;\r
+ }\r
+ Context.NewBlock = TRUE;\r
+ Context.Block = Block;\r
+ } else {\r
+ Context.NewBlock = FALSE;\r
ResponseBody.Body = (CHAR8*) Block;\r
ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE;\r
Status = HttpIoRecvResponse (\r
ResponseBody.Body = (CHAR8*) Block;\r
ResponseBody.BodyLength = HTTP_BOOT_BLOCK_SIZE;\r
Status = HttpIoRecvResponse (\r
//\r
// Parse the new received block of the message-body, the block will be saved in cache.\r
//\r
//\r
// Parse the new received block of the message-body, the block will be saved in cache.\r
//\r
- Context.NewBlock = TRUE;\r
- Context.Block = Block;\r
Status = HttpParseMessageBody (\r
Parser,\r
ResponseBody.BodyLength,\r
Status = HttpParseMessageBody (\r
Parser,\r
ResponseBody.BodyLength,\r
//\r
// 4. Save the cache item to driver's cache list and return.\r
//\r
//\r
// 4. Save the cache item to driver's cache list and return.\r
//\r
Cache->EntityLength = ContentLength;\r
InsertTailList (&Private->CacheList, &Cache->Link);\r
}\r
Cache->EntityLength = ContentLength;\r
InsertTailList (&Private->CacheList, &Cache->Link);\r
}\r