winhttp: Drain frames until close frame in socket_close().

Signed-off-by: Paul Gofman <pgofman@codeweavers.com>
Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Paul Gofman 2022-01-24 12:43:11 +03:00 committed by Alexandre Julliard
parent ea60e4678c
commit c892634244
2 changed files with 20 additions and 7 deletions

View File

@ -3686,9 +3686,16 @@ static DWORD socket_close( struct socket *socket, USHORT status, const void *rea
socket->state = SOCKET_STATE_SHUTDOWN;
}
if ((ret = receive_frame( socket, &count, &socket->opcode ))) goto done;
if (socket->opcode != SOCKET_OPCODE_CLOSE ||
(count && (count < sizeof(socket->status) || count > sizeof(socket->status) + sizeof(socket->reason))))
while (1)
{
if ((ret = receive_frame( socket, &count, &socket->opcode ))) goto done;
if (socket->opcode == SOCKET_OPCODE_CLOSE) break;
socket->read_size = count;
if ((ret = socket_drain( socket ))) goto done;
}
if ((count && (count < sizeof(socket->status) || count > sizeof(socket->status) + sizeof(socket->reason))))
{
ret = ERROR_WINHTTP_INVALID_SERVER_RESPONSE;
goto done;

View File

@ -659,6 +659,7 @@ static const struct notification websocket_test[] =
{ winhttp_receive_response, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE, NF_SIGNAL },
{ winhttp_websocket_complete_upgrade, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED, NF_SIGNAL },
{ winhttp_websocket_send, WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE, NF_SIGNAL },
{ winhttp_websocket_send, WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE, NF_SIGNAL },
{ winhttp_websocket_shutdown, WINHTTP_CALLBACK_STATUS_SHUTDOWN_COMPLETE, NF_SIGNAL },
{ winhttp_websocket_receive, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, NF_SIGNAL },
{ winhttp_websocket_receive, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, NF_SIGNAL },
@ -681,6 +682,7 @@ static void test_websocket(BOOL secure)
char buffer[1024];
USHORT close_status;
DWORD protocols, flags;
unsigned int i;
if (!pWinHttpWebSocketCompleteUpgrade)
{
@ -788,10 +790,14 @@ static void test_websocket(BOOL secure)
ok( err == ERROR_SUCCESS, "got %u\n", err );
WaitForSingleObject( info.wait, INFINITE );
setup_test( &info, winhttp_websocket_send, __LINE__ );
err = pWinHttpWebSocketSend( socket, 0, (void *)"hello", sizeof("hello") );
ok( err == ERROR_SUCCESS, "got %u\n", err );
WaitForSingleObject( info.wait, INFINITE );
for (i = 0; i < 2; ++i)
{
setup_test( &info, winhttp_websocket_send, __LINE__ );
err = pWinHttpWebSocketSend( socket, WINHTTP_WEB_SOCKET_BINARY_MESSAGE_BUFFER_TYPE,
(void*)"hello", sizeof("hello") );
ok( err == ERROR_SUCCESS, "got %u\n", err );
WaitForSingleObject( info.wait, INFINITE );
}
setup_test( &info, winhttp_websocket_shutdown, __LINE__ );
err = pWinHttpWebSocketShutdown( socket, 1000, (void *)"success", sizeof("success") );