]> granicus.if.org Git - curl/commitdiff
SOCKOPTFUNCTION: callback can say already-connected
authorDaniel Stenberg <daniel@haxx.se>
Wed, 9 Feb 2011 14:46:41 +0000 (15:46 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 17 Feb 2011 21:32:01 +0000 (22:32 +0100)
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.

RELEASE-NOTES
include/curl/curl.h
lib/connect.c

index ccd2eba80f1fd4c44c65c22e27736835f52328ce..363352a2be05e69484fc1995b3ab27c3ad21062a 100644 (file)
@@ -9,7 +9,7 @@ Curl and libcurl 7.21.5
 
 This release includes the following changes:
 
- o 
+ o SOCKOPTFUNCTION: callback can say already-connected
 
 This release includes the following bugfixes:
 
index 4744f48305a1b8a3fa8f9f7cc8866091ca9eac3e..73713dd070629566f419baa8daecc5e08128aa24 100644 (file)
@@ -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);
index fb21fb7df5a38150d9fe8f2ce35e8946e1abddba..261b2150e9287569236dc1f213e89abe0833365d 100644 (file)
@@ -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! */