On Wed, 9 Feb 2011, Keean Schupke wrote:
Okay, That makes complete sense. I would be completely happy with returning something from CURLOPT_SOCKOPTFUNCTION to indicate I do not want libcurl to try and connect the socket.
Okay, so what do you say about a patch similar to what I attach here?Note that I just fixed a bug in there immediately before producing this patch, so you most probably need to apply this to the current git or do some manual editing to make it apply on older code.
(This is a new feature so we're not merging this into master until after the pending release, but we can still make it work as we like.)
-- / daniel.haxx.se
From 4e9e5f6d0bbc1d7caa88ebcfa85794f1e0d16fc9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg <[email protected]> Date: Wed, 9 Feb 2011 15:46:41 +0100 Subject: [PATCH] SOCKOPTFUNCTION: callback can say already-connected Introducing a few CURL_SOCKOPT* defines for conveniance. The new CURL_SOCKOPT_ALREADY_CONNECTED signals to libcurl that the socket is to be treated as already connected and thus it will skip the connect() call. --- include/curl/curl.h | 7 +++++++ lib/connect.c | 12 ++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/curl/curl.h b/include/curl/curl.h index bf65420..7c5547f 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -315,6 +315,13 @@ typedef enum { CURLSOCKTYPE_LAST /* never use */ } curlsocktype; +/* The return code from the sockopt_callback can signal information back + to libcurl: */ +#define CURL_SOCKOPT_OK 0 +#define CURL_SOCKOPT_ERROR 1 /* causes libcurl to abort and return + CURLE_ABORTED_BY_CALLBACK */ +#define CURL_SOCKOPT_ALREADY_CONNECTED 2 + typedef int (*curl_sockopt_callback)(void *clientp, curl_socket_t curlfd, curlsocktype purpose); diff --git a/lib/connect.c b/lib/connect.c index fb21fb7..261b215 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -837,7 +837,7 @@ singleipconnect(struct connectdata *conn, struct Curl_sockaddr_ex addr; int rc; int error; - bool isconnected; + bool isconnected = FALSE; struct SessionHandle *data = conn->data; curl_socket_t sockfd; CURLcode res = CURLE_OK; @@ -924,7 +924,10 @@ singleipconnect(struct connectdata *conn, error = data->set.fsockopt(data->set.sockopt_client, sockfd, CURLSOCKTYPE_IPCXN); - if(error) { + + if(error == CURL_SOCKOPT_ALREADY_CONNECTED) + isconnected = TRUE; + else if(error) { sclose(sockfd); /* close the socket and bail out */ return CURLE_ABORTED_BY_CALLBACK; } @@ -941,7 +944,7 @@ singleipconnect(struct connectdata *conn, curlx_nonblock(sockfd, TRUE); /* Connect TCP sockets, bind UDP */ - if(conn->socktype == SOCK_STREAM) { + if(!isconnected && (conn->socktype == SOCK_STREAM)) { rc = connect(sockfd, &addr.sa_addr, addr.addrlen); conn->connecttime = Curl_tvnow(); if(conn->num_addr > 1) @@ -989,7 +992,8 @@ singleipconnect(struct connectdata *conn, return CURLE_OK; } - isconnected = verifyconnect(sockfd, &error); + if(!isconnected) + isconnected = verifyconnect(sockfd, &error); if(!rc && isconnected) { /* we are connected, awesome! */ -- 1.7.1
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html
