On Wed, 6 Jan 2010, Daniel Stenberg wrote:
Your description here makes it sound as if the problem is rather while
waiting for the connect to happen or fail. I'll proceed with committing the
previously mentioned patch since I do believe it is still the right thing,
and then I'll read more code to see if I can understand why you don't get
progress callbacks during the connection phase.
I'm not sure if I should laugh or cry, but I found almost the exact same
mistake in the connect code as I found in the c-ares name resolving and I've
attached my take at fixing this. Please try it out and let me know how it
works! I expect this patch to work on earlier libcurl versions as well as
latest CVS.
This should make the progress callback get called once per second even during
very slow connect attempts.
--
/ daniel.haxx.se
Index: lib/connect.c
===================================================================
RCS file: /cvsroot/curl/curl/lib/connect.c,v
retrieving revision 1.224
diff -u -p -r1.224 connect.c
--- lib/connect.c 30 Dec 2009 17:59:56 -0000 1.224
+++ lib/connect.c 6 Jan 2010 23:31:18 -0000
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2009, Daniel Stenberg, <[email protected]>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <[email protected]>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -192,7 +192,8 @@ long Curl_timeleft(struct connectdata *c
#define WAITCONN_FDSET_ERROR 2
static
-int waitconnect(curl_socket_t sockfd, /* socket */
+int waitconnect(struct connectdata *conn,
+ curl_socket_t sockfd, /* socket */
long timeout_msec)
{
int rc;
@@ -203,21 +204,34 @@ int waitconnect(curl_socket_t sockfd, /*
(void)verifyconnect(sockfd, NULL);
#endif
- /* now select() until we get connect or timeout */
- rc = Curl_socket_ready(CURL_SOCKET_BAD, sockfd, (int)timeout_msec);
- if(-1 == rc)
- /* error, no connect here, try next */
- return WAITCONN_SELECT_ERROR;
-
- else if(0 == rc)
- /* timeout, no connect today */
- return WAITCONN_TIMEOUT;
-
- if(rc & CURL_CSELECT_ERR)
- /* error condition caught */
- return WAITCONN_FDSET_ERROR;
+ while(1) {
- /* we have a connect! */
+ /* now select() until we get connect or timeout */
+ rc = Curl_socket_ready(CURL_SOCKET_BAD, sockfd, (int)(timeout_msec>1000?
+ 1000:timeout_msec));
+
+ if(Curl_pgrsUpdate(conn))
+ return CURLE_ABORTED_BY_CALLBACK;
+
+ if(-1 == rc)
+ /* error, no connect here, try next */
+ return WAITCONN_SELECT_ERROR;
+
+ else if(0 == rc) {
+ /* timeout */
+ timeout_msec -= 1000;
+ if(timeout_msec <= 0)
+ return WAITCONN_TIMEOUT;
+
+ continue;
+ }
+
+ if(rc & CURL_CSELECT_ERR)
+ /* error condition caught */
+ return WAITCONN_FDSET_ERROR;
+
+ break;
+ }
return WAITCONN_CONNECTED;
}
@@ -553,7 +567,7 @@ CURLcode Curl_is_connected(struct connec
Curl_expire(data, allow);
/* check for connect without timeout as we want to return immediately */
- rc = waitconnect(sockfd, 0);
+ rc = waitconnect(conn, sockfd, 0);
if(WAITCONN_CONNECTED == rc) {
int error;
@@ -823,7 +837,7 @@ singleipconnect(struct connectdata *conn
case EAGAIN:
#endif
#endif
- rc = waitconnect(sockfd, timeout_ms);
+ rc = waitconnect(conn, sockfd, timeout_ms);
break;
default:
/* unknown error, fallthrough and try another address! */
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html