From cf8704ccdf60a34ba7862a0848724b9862158c86 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 4 Mar 2001 16:34:20 +0000 Subject: 7.7 alpha 2 commit --- lib/url.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/url.c') diff --git a/lib/url.c b/lib/url.c index 9318d4132..123e5d480 100644 --- a/lib/url.c +++ b/lib/url.c @@ -575,6 +575,32 @@ CURLcode curl_disconnect(CURLconnect *c_connect) return CURLE_OK; } +/* + * This function should return TRUE if the socket is to be assumed to + * be dead. Most commonly this happens when the server has closed the + * connection due to inactivity. + */ +static bool SocketIsDead(int sock) +{ + int sval; + bool ret_val = TRUE; + fd_set check_set; + struct timeval to; + + FD_ZERO(&check_set); + FD_SET(sock,&check_set); + + to.tv_sec = 0; + to.tv_usec = 1; + + sval = select(sock + 1, &check_set, 0, 0, &to); + if(sval == 0) + /* timeout */ + ret_val = FALSE; + + return ret_val; +} + /* * Given one filled in connection struct, this function should detect if there * already is one that have all the significant details exactly the same and @@ -609,6 +635,16 @@ ConnectionExists(struct UrlData *data, continue; } } + { + bool dead; + dead = SocketIsDead(check->firstsocket); + if(dead) { + infof(data, "Connection %d seems to be dead!\n", i); + curl_disconnect(check); /* disconnect resources */ + data->connects[i]=NULL; /* nothing here */ + continue; /* try another one now */ + } + } *usethis = check; return TRUE; /* yes, we found one to use! */ } @@ -909,7 +945,6 @@ static CURLcode ConnectPlease(struct UrlData *data, return CURLE_OK; } - static CURLcode _connect(CURL *curl, CURLconnect **in_connect, bool allow_port) /* allow data->use_port ? */ -- cgit v1.2.3