Module: wine Branch: master Commit: d1d65c9b211fc79d43fbe1c3f9c61899720807c5 URL: http://source.winehq.org/git/wine.git/?a=commit;h=d1d65c9b211fc79d43fbe1c3f9...
Author: Jacek Caban jacek@codeweavers.com Date: Tue Jul 18 00:25:06 2017 +0200
winhttp: Merge netconn_create and netconn_connect implementations.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Hans Leidekker hans@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/winhttp/net.c | 62 ++++++++++++++++++++---------------------- dlls/winhttp/request.c | 8 +----- dlls/winhttp/winhttp_private.h | 3 +- 3 files changed, 32 insertions(+), 41 deletions(-)
diff --git a/dlls/winhttp/net.c b/dlls/winhttp/net.c index 76e49da..32d3624 100644 --- a/dlls/winhttp/net.c +++ b/dlls/winhttp/net.c @@ -299,9 +299,14 @@ void netconn_unload( void ) #endif }
-netconn_t *netconn_create( const struct sockaddr_storage *sockaddr ) +netconn_t *netconn_create( const struct sockaddr_storage *sockaddr, int timeout ) { netconn_t *conn; + unsigned int addr_len; + BOOL ret = FALSE; + int res; + ULONG state; + conn = heap_alloc_zero(sizeof(*conn)); if (!conn) return NULL; conn->sockaddr = *sockaddr; @@ -312,36 +317,6 @@ netconn_t *netconn_create( const struct sockaddr_storage *sockaddr ) heap_free(conn); return NULL; } - return conn; -} - -BOOL netconn_close( netconn_t *conn ) -{ - int res; - - if (conn->secure) - { - heap_free( conn->peek_msg_mem ); - heap_free(conn->ssl_buf); - heap_free(conn->extra_buf); - DeleteSecurityContext(&conn->ssl_ctx); - } - res = closesocket( conn->socket ); - heap_free(conn); - if (res == -1) - { - set_last_error( sock_get_error( errno ) ); - return FALSE; - } - return TRUE; -} - -BOOL netconn_connect( netconn_t *conn, int timeout ) -{ - unsigned int addr_len; - BOOL ret = FALSE; - int res; - ULONG state;
switch (conn->sockaddr.ss_family) { @@ -405,8 +380,31 @@ BOOL netconn_connect( netconn_t *conn, int timeout ) { WARN("unable to connect to host (%d)\n", res); set_last_error( res ); + netconn_close( conn ); + return NULL; } - return ret; + return conn; +} + +BOOL netconn_close( netconn_t *conn ) +{ + int res; + + if (conn->secure) + { + heap_free( conn->peek_msg_mem ); + heap_free(conn->ssl_buf); + heap_free(conn->extra_buf); + DeleteSecurityContext(&conn->ssl_ctx); + } + res = closesocket( conn->socket ); + heap_free(conn); + if (res == -1) + { + set_last_error( sock_get_error( errno ) ); + return FALSE; + } + return TRUE; }
BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_flags ) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 5076935..5afc768 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -1021,19 +1021,13 @@ static BOOL open_connection( request_t *request )
send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER, addressW, 0 );
- if (!(netconn = netconn_create( &connect->sockaddr ))) + if (!(netconn = netconn_create( &connect->sockaddr, request->connect_timeout ))) { heap_free( addressW ); return FALSE; } netconn_set_timeout( netconn, TRUE, request->send_timeout ); netconn_set_timeout( netconn, FALSE, request->recv_timeout ); - if (!netconn_connect( netconn, request->connect_timeout )) - { - netconn_close( netconn ); - heap_free( addressW ); - return FALSE; - } if (request->hdr.flags & WINHTTP_FLAG_SECURE) { if (connect->session->proxy_server && diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h index 480311b..611dc43 100644 --- a/dlls/winhttp/winhttp_private.h +++ b/dlls/winhttp/winhttp_private.h @@ -283,8 +283,7 @@ void send_callback( object_header_t *, DWORD, LPVOID, DWORD ) DECLSPEC_HIDDEN; void close_connection( request_t * ) DECLSPEC_HIDDEN;
BOOL netconn_close( netconn_t * ) DECLSPEC_HIDDEN; -BOOL netconn_connect( netconn_t *, int ) DECLSPEC_HIDDEN; -netconn_t *netconn_create( const struct sockaddr_storage * ) DECLSPEC_HIDDEN; +netconn_t *netconn_create( const struct sockaddr_storage *, int ) DECLSPEC_HIDDEN; void netconn_unload( void ) DECLSPEC_HIDDEN; ULONG netconn_query_data_available( netconn_t * ) DECLSPEC_HIDDEN; BOOL netconn_recv( netconn_t *, void *, size_t, int, int * ) DECLSPEC_HIDDEN;