[PATCH v2 3/3] winhttp: Execute WinHttpReadData() synchronously if the data is available.

Paul Gofman pgofman at codeweavers.com
Wed Aug 25 04:57:54 CDT 2021


Fixes eFootball PES 2021 in game contents download.

Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
    v2:
        - fix test for Win7;
        - set last error to reflect actual async status.

 dlls/winhttp/request.c            | 9 ++++++---
 dlls/winhttp/tests/notification.c | 5 +++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 03f895a7fdb..001fff74a87 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -2931,6 +2931,7 @@ BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, L
 {
     DWORD ret;
     struct request *request;
+    BOOL async;
 
     TRACE("%p, %p, %d, %p\n", hrequest, buffer, to_read, read);
 
@@ -2946,7 +2947,8 @@ BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, L
         return FALSE;
     }
 
-    if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC)
+    if ((async = request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) && !end_of_read_data( request )
+                                                                   && !query_data_ready( request ))
     {
         struct read_data *r;
 
@@ -2962,12 +2964,13 @@ BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, L
             release_object( &request->hdr );
             free( r );
         }
+        else ret = ERROR_IO_PENDING;
     }
-    else ret = read_data( request, buffer, to_read, read, FALSE );
+    else ret = read_data( request, buffer, to_read, read, async );
 
     release_object( &request->hdr );
     SetLastError( ret );
-    return !ret;
+    return !ret || ret == ERROR_IO_PENDING;
 }
 
 static DWORD write_data( struct request *request, const void *buffer, DWORD to_write, DWORD *written, BOOL async )
diff --git a/dlls/winhttp/tests/notification.c b/dlls/winhttp/tests/notification.c
index 7d1bfa78a49..4cfffe6687e 100644
--- a/dlls/winhttp/tests/notification.c
+++ b/dlls/winhttp/tests/notification.c
@@ -615,6 +615,11 @@ static void test_async( void )
 
     WaitForSingleObject( info.wait, INFINITE );
 
+    ok(info.last_status == WINHTTP_CALLBACK_STATUS_READ_COMPLETE, "got status %#x.\n", status);
+    ok((err == ERROR_SUCCESS && info.last_thread_id == GetCurrentThreadId())
+            || (err == ERROR_IO_PENDING && info.last_thread_id != GetCurrentThreadId()),
+            "Got unexpected thread %#x, err %#x.\n", info.last_thread_id, err);
+
     setup_test( &info, winhttp_close_handle, __LINE__ );
     WinHttpCloseHandle( req );
     WinHttpCloseHandle( con );
-- 
2.31.1




More information about the wine-devel mailing list