From 7570696c57d446f163050c2befb78b8fc6cfeb02 Mon Sep 17 00:00:00 2001 From: Jiaxin Wu Date: Tue, 31 May 2016 22:17:28 +0800 Subject: [PATCH] NetworkPkg: Handling timeout case in httpboot driver This patch is used to handle timeout case when downloading the message. The Status in the token should also be checked to handle any response error case including timeout case. Cc: Fu Siyuan Cc: Ye Ting Cc: Zhang Lubo Cc: Hegde Nagaraj P Cc: Gary Lin Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiaxin Wu Reviewed-by: Gary Lin Reviewed-by: Hegde Nagaraj P Reviewed-by: Ye Ting Tested-by: Gary Lin Tested-by: Hegde Nagaraj P --- NetworkPkg/HttpBootDxe/HttpBootClient.c | 10 ++++-- NetworkPkg/HttpBootDxe/HttpBootClient.h | 1 + NetworkPkg/HttpBootDxe/HttpBootSupport.c | 46 +++++++++++++++++++++++- NetworkPkg/HttpBootDxe/HttpBootSupport.h | 2 ++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.c b/NetworkPkg/HttpBootDxe/HttpBootClient.c index 46cf9ca6fb..378bf02880 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.c +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.c @@ -1008,7 +1008,10 @@ HttpBootGetBootFile ( FALSE, &ResponseBody ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { + if (EFI_ERROR (ResponseBody.Status)) { + Status = ResponseBody.Status; + } goto ERROR_6; } ReceivedSize += ResponseBody.BodyLength; @@ -1045,7 +1048,10 @@ HttpBootGetBootFile ( FALSE, &ResponseBody ); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) { + if (EFI_ERROR (ResponseBody.Status)) { + Status = ResponseBody.Status; + } goto ERROR_6; } diff --git a/NetworkPkg/HttpBootDxe/HttpBootClient.h b/NetworkPkg/HttpBootDxe/HttpBootClient.h index 2fd7dfc716..2c32341460 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootClient.h +++ b/NetworkPkg/HttpBootDxe/HttpBootClient.h @@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define __EFI_HTTP_BOOT_HTTP_H__ #define HTTP_BOOT_REQUEST_TIMEOUT 5000 // 5 seconds in uints of millisecond. +#define HTTP_BOOT_RESPONSE_TIMEOUT 5000 // 5 seconds in uints of millisecond. #define HTTP_BOOT_BLOCK_SIZE 1500 diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c index 66eca783af..9410bf9e15 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c @@ -754,6 +754,21 @@ HttpIoCreateIo ( HttpIo->RspToken.Event = Event; HttpIo->RspToken.Message = &HttpIo->RspMessage; + // + // Create TimeoutEvent for response + // + Status = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &Event + ); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + HttpIo->TimeoutEvent = Event; + return EFI_SUCCESS; ON_ERROR: @@ -789,6 +804,11 @@ HttpIoDestroyIo ( if (Event != NULL) { gBS->CloseEvent (Event); } + + Event = HttpIo->TimeoutEvent; + if (Event != NULL) { + gBS->CloseEvent (Event); + } Http = HttpIo->Http; if (Http != NULL) { @@ -902,6 +922,14 @@ HttpIoRecvResponse ( return EFI_INVALID_PARAMETER; } + // + // Start the timer, and wait Timeout seconds to receive the header packet. + // + Status = gBS->SetTimer (HttpIo->TimeoutEvent, TimerRelative, HTTP_BOOT_RESPONSE_TIMEOUT * TICKS_PER_MS); + if (EFI_ERROR (Status)) { + return Status; + } + // // Queue the response token to HTTP instances. // @@ -924,16 +952,32 @@ HttpIoRecvResponse ( ); if (EFI_ERROR (Status)) { + gBS->SetTimer (HttpIo->TimeoutEvent, TimerCancel, 0); return Status; } // // Poll the network until receive finish. // - while (!HttpIo->IsRxDone) { + while (!HttpIo->IsRxDone && ((HttpIo->TimeoutEvent == NULL) || EFI_ERROR (gBS->CheckEvent (HttpIo->TimeoutEvent)))) { Http->Poll (Http); } + gBS->SetTimer (HttpIo->TimeoutEvent, TimerCancel, 0); + + if (!HttpIo->IsRxDone) { + // + // Timeout occurs, cancel the response token. + // + Http->Cancel (Http, &HttpIo->RspToken); + + Status = EFI_TIMEOUT; + + return Status; + } else { + HttpIo->IsRxDone = FALSE; + } + // // Store the received data into the wrapper. // diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBootDxe/HttpBootSupport.h index 28e8005d21..4d024277b5 100644 --- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h +++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h @@ -196,6 +196,8 @@ typedef struct { BOOLEAN IsTxDone; BOOLEAN IsRxDone; + + EFI_EVENT TimeoutEvent; } HTTP_IO; // -- 2.39.2