From: Sebastian Lackner Subject: [4/5] wininet: Handle async mode in HTTPREQ_ReadFile. (resend) Message-Id: <77b479cd-a8ca-91ff-7d12-c8dc70ca2881@fds-team.de> Date: Thu, 28 Apr 2016 05:14:47 +0200 From: Michael Müller Signed-off-by: Michael Müller Signed-off-by: Sebastian Lackner --- Yes, using ReadFileEx would be better, but it would break the tests. As mentioned in the previous patch, a lot of things are still going wrong with regards to notification events. They should only be triggered when receiving data from the wire, not when ReadFile falls back to a copy operation. dlls/wininet/http.c | 60 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 66ee6ba..775ff61 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -3101,23 +3101,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; @@ -3241,6 +3224,49 @@ 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 ); + return res; + } + 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 ); + + return res; +} + typedef struct { task_header_t hdr; DWORD *ret_size; -- 2.8.0