Commit 45872934 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

winhttp: Factor out send_socket_shutdown() function.

parent 5ea5db90
......@@ -3650,11 +3650,6 @@ DWORD WINAPI WinHttpWebSocketReceive( HINTERNET hsocket, void *buf, DWORD len, D
return ret;
}
static DWORD socket_shutdown( struct socket *socket, USHORT status, const void *reason, DWORD len )
{
return send_frame( socket, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE, NULL );
}
static void CALLBACK task_socket_shutdown( TP_CALLBACK_INSTANCE *instance, void *ctx, TP_WORK *work )
{
struct socket_shutdown *s = ctx;
......@@ -3662,7 +3657,7 @@ static void CALLBACK task_socket_shutdown( TP_CALLBACK_INSTANCE *instance, void
TRACE("running %p\n", work);
ret = socket_shutdown( s->socket, s->status, s->reason, s->len );
ret = send_frame( s->socket, SOCKET_OPCODE_CLOSE, s->status, s->reason, s->len, TRUE, NULL );
send_io_complete( &s->socket->hdr );
if (!ret) send_callback( &s->socket->hdr, WINHTTP_CALLBACK_STATUS_SHUTDOWN_COMPLETE, NULL, 0 );
......@@ -3679,27 +3674,11 @@ static void CALLBACK task_socket_shutdown( TP_CALLBACK_INSTANCE *instance, void
free( s );
}
DWORD WINAPI WinHttpWebSocketShutdown( HINTERNET hsocket, USHORT status, void *reason, DWORD len )
static DWORD send_socket_shutdown( struct socket *socket, USHORT status, const void *reason, DWORD len,
BOOL send_callback)
{
struct socket *socket;
DWORD ret;
TRACE("%p, %u, %p, %u\n", hsocket, status, reason, len);
if ((len && !reason) || len > sizeof(socket->reason)) return ERROR_INVALID_PARAMETER;
if (!(socket = (struct socket *)grab_object( hsocket ))) return ERROR_INVALID_HANDLE;
if (socket->hdr.type != WINHTTP_HANDLE_TYPE_SOCKET)
{
release_object( &socket->hdr );
return ERROR_WINHTTP_INCORRECT_HANDLE_TYPE;
}
if (socket->state >= SOCKET_STATE_SHUTDOWN)
{
release_object( &socket->hdr );
return ERROR_INVALID_OPERATION;
}
socket->state = SOCKET_STATE_SHUTDOWN;
if (socket->request->connect->hdr.flags & WINHTTP_FLAG_ASYNC)
......@@ -3721,8 +3700,33 @@ DWORD WINAPI WinHttpWebSocketShutdown( HINTERNET hsocket, USHORT status, void *r
free( s );
}
}
else ret = socket_shutdown( socket, status, reason, len );
else ret = send_frame( socket, SOCKET_OPCODE_CLOSE, status, reason, len, TRUE, NULL );
return ret;
}
DWORD WINAPI WinHttpWebSocketShutdown( HINTERNET hsocket, USHORT status, void *reason, DWORD len )
{
struct socket *socket;
DWORD ret;
TRACE("%p, %u, %p, %u\n", hsocket, status, reason, len);
if ((len && !reason) || len > sizeof(socket->reason)) return ERROR_INVALID_PARAMETER;
if (!(socket = (struct socket *)grab_object( hsocket ))) return ERROR_INVALID_HANDLE;
if (socket->hdr.type != WINHTTP_HANDLE_TYPE_SOCKET)
{
release_object( &socket->hdr );
return ERROR_WINHTTP_INCORRECT_HANDLE_TYPE;
}
if (socket->state >= SOCKET_STATE_SHUTDOWN)
{
release_object( &socket->hdr );
return ERROR_INVALID_OPERATION;
}
ret = send_socket_shutdown( socket, status, reason, len, TRUE );
release_object( &socket->hdr );
return ret;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment