Commit d1d65c9b authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

winhttp: Merge netconn_create and netconn_connect implementations.

parent 3e602416
......@@ -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 )
......
......@@ -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 &&
......
......@@ -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;
......
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