winhttp(6/6): Implement connect timeout
Juan Lang
juan.lang at gmail.com
Tue Jul 21 16:56:17 CDT 2009
--Juan
-------------- next part --------------
From 1b3efbd2523e5c1a4cc8ab3b83c376bb6c658f1c Mon Sep 17 00:00:00 2001
From: Juan Lang <juan.lang at gmail.com>
Date: Tue, 21 Jul 2009 14:47:52 -0700
Subject: [PATCH 10/10] Implement connect timeout
---
dlls/winhttp/net.c | 22 ++++++++++++++++++++--
dlls/winhttp/request.c | 2 +-
dlls/winhttp/session.c | 6 +++++-
dlls/winhttp/winhttp_private.h | 3 ++-
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/dlls/winhttp/net.c b/dlls/winhttp/net.c
index 6f2d5f5..98f82aa 100644
--- a/dlls/winhttp/net.c
+++ b/dlls/winhttp/net.c
@@ -33,6 +33,7 @@
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
+#include <fcntl.h>
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
@@ -287,9 +288,26 @@ BOOL netconn_close( netconn_t *conn )
return TRUE;
}
-BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len )
+BOOL netconn_connect( netconn_t *conn, const struct sockaddr *sockaddr, unsigned int addr_len, int timeout )
{
- if (connect( conn->socket, sockaddr, addr_len ) == -1)
+ int flags = -1, res;
+
+ if (timeout > 0)
+ flags = fcntl( conn->socket, F_GETFL, 0 );
+ if (flags != -1)
+ fcntl( conn->socket, F_SETFL, flags | O_NONBLOCK );
+ res = connect( conn->socket, sockaddr, addr_len );
+ if (res == -1 && (errno == EINPROGRESS || errno == EAGAIN))
+ {
+ struct pollfd pfd;
+
+ pfd.fd = conn->socket;
+ pfd.events = POLLOUT;
+ res = poll( &pfd, 1, timeout );
+ }
+ if (flags != -1)
+ fcntl( conn->socket, F_SETFL, flags );
+ if (res == -1)
{
WARN("unable to connect to host (%s)\n", strerror(errno));
set_last_error( sock_get_error( errno ) );
diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 344bb14..7d37126 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -922,7 +922,7 @@ static BOOL open_connection( request_t *request )
}
netconn_set_timeout( &request->netconn, TRUE, request->send_timeout );
netconn_set_timeout( &request->netconn, FALSE, request->recv_timeout );
- if (!netconn_connect( &request->netconn, (struct sockaddr *)&connect->sockaddr, slen ))
+ if (!netconn_connect( &request->netconn, (struct sockaddr *)&connect->sockaddr, slen, request->connect_timeout ))
{
netconn_close( &request->netconn );
heap_free( addressW );
diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c
index 81113e4..454374e 100644
--- a/dlls/winhttp/session.c
+++ b/dlls/winhttp/session.c
@@ -33,6 +33,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
+#define DEFAULT_CONNECT_TIMEOUT 60000
#define DEFAULT_SEND_TIMEOUT 30000
#define DEFAULT_RECEIVE_TIMEOUT 30000
@@ -636,6 +637,7 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR o
list_add_head( &connect->hdr.children, &request->hdr.entry );
if (!netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE )) goto end;
+ request->connect_timeout = DEFAULT_CONNECT_TIMEOUT;
request->send_timeout = DEFAULT_SEND_TIMEOUT;
request->recv_timeout = DEFAULT_RECEIVE_TIMEOUT;
@@ -1167,7 +1169,7 @@ BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int
return FALSE;
}
- FIXME("resolve and connect timeout not supported\n");
+ FIXME("resolve timeout not supported\n");
if (!(request = (request_t *)grab_object( handle )))
{
@@ -1182,6 +1184,8 @@ BOOL WINAPI WinHttpSetTimeouts( HINTERNET handle, int resolve, int connect, int
return FALSE;
}
+ request->connect_timeout = connect;
+
if (send < 0) send = 0;
request->send_timeout = send;
diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h
index 97c8f90..83df0c0 100644
--- a/dlls/winhttp/winhttp_private.h
+++ b/dlls/winhttp/winhttp_private.h
@@ -139,6 +139,7 @@ typedef struct
LPWSTR version;
LPWSTR raw_headers;
netconn_t netconn;
+ int connect_timeout;
int send_timeout;
int recv_timeout;
LPWSTR status_text;
@@ -206,7 +207,7 @@ void send_callback( object_header_t *, DWORD, LPVOID, DWORD );
void close_connection( request_t * );
BOOL netconn_close( netconn_t * );
-BOOL netconn_connect( netconn_t *, const struct sockaddr *, unsigned int );
+BOOL netconn_connect( netconn_t *, const struct sockaddr *, unsigned int, int );
BOOL netconn_connected( netconn_t * );
BOOL netconn_create( netconn_t *, int, int, int );
BOOL netconn_get_next_line( netconn_t *, char *, DWORD * );
--
1.6.3.2
More information about the wine-patches
mailing list