NetworkPkg: HttpDxe response/cancel issue fix

Remove timeout check for http body message receive. It should be handled
in HttpBootDxe driver for http response unblocking implementation. After
timeout removed, the Wrap date should not be freed immediately. Only the
TCP CompletionToken in Wrap date is canceled or signaled, the Wrap date
could be freed.
In addition, Http cancel token is also incorrect. Tcp Cancel should be called
to cancel TCP CompletionToken in Wrap date before close it directly. Otherwise,
some exception behavior may happened.
This patch also refine the coding style for HttpDxe driver.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Cc: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Cc: Gary Lin <glin@suse.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Reviewed-by: Gary Lin <glin@suse.com>
Reviewed-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Tested-by: Gary Lin <glin@suse.com>
Tested-by: Hegde Nagaraj P <nagaraj-p.hegde@hpe.com>
This commit is contained in:
Jiaxin Wu
2016-05-31 22:17:27 +08:00
parent 5ffe214ae9
commit 30526a51dd
3 changed files with 77 additions and 103 deletions

View File

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