From: Sebastian Lackner Subject: [3/5] wininet: Handle async mode in HTTPREQ_ReadFile. (resend) Message-Id: Date: Tue, 26 Apr 2016 23:38:16 +0200 From: Michael Müller Signed-off-by: Michael Müller Signed-off-by: Sebastian Lackner --- dlls/wininet/http.c | 61 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 2774ab0..6c2c567 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -3105,23 +3105,6 @@ static BOOL drain_content(http_request_t *req, BOOL blocking) return ret; } -static DWORD HTTPREQ_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DWORD *read) -{ - http_request_t *req = (http_request_t*)hdr; - DWORD res; - - EnterCriticalSection( &req->read_section ); - if(hdr->dwError == INTERNET_HANDLE_IN_USE) - hdr->dwError = ERROR_INTERNET_INTERNAL_ERROR; - - res = HTTPREQ_Read(req, buffer, size, read); - if(res == ERROR_SUCCESS) - res = hdr->dwError; - LeaveCriticalSection( &req->read_section ); - - return res; -} - typedef struct { task_header_t hdr; void *buf; @@ -3238,6 +3221,50 @@ static DWORD HTTPREQ_WriteFile(object_header_t *hdr, const void *buffer, DWORD s return res; } +static DWORD HTTPREQ_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DWORD *read) +{ + http_request_t *req = (http_request_t*)hdr; + DWORD res; + + if (req->session->appInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC) + { + read_file_ex_task_t *task; + + if (TryEnterCriticalSection( &req->read_section )) + { + if (get_avail_data(req)) + { + res = HTTPREQ_Read(req, buffer, size, read); + LeaveCriticalSection( &req->read_section ); + goto done; + } + LeaveCriticalSection( &req->read_section ); + } + + task = alloc_async_task(&req->hdr, AsyncReadFileExProc, sizeof(*task)); + task->buf = buffer; + task->size = size; + task->ret_read = read; + + *read = 0; + INTERNET_AsyncCall(&task->hdr); + + return ERROR_IO_PENDING; + } + + EnterCriticalSection( &req->read_section ); + if(hdr->dwError == INTERNET_HANDLE_IN_USE) + hdr->dwError = ERROR_INTERNET_INTERNAL_ERROR; + + res = HTTPREQ_Read(req, buffer, size, read); + if(res == ERROR_SUCCESS) + res = hdr->dwError; + LeaveCriticalSection( &req->read_section ); + +done: + return res; +} + typedef struct { task_header_t hdr; DWORD *ret_size; -- 2.8.0