aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-03-25 13:37:18 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-03-25 13:37:18 +0000
commitbb3d6e8552f428bd0c2624854403d36ab3cf163d (patch)
tree3844a61e49ad9a1bdddd671681bfc1845f04ce95 /lib
parent189c2f498987e443836aada953ace7795202e350 (diff)
tcp-nodelay patch by Joe Halpin
Diffstat (limited to 'lib')
-rw-r--r--lib/connect.c24
-rw-r--r--lib/url.c8
-rw-r--r--lib/urldata.h3
3 files changed, 35 insertions, 0 deletions
diff --git a/lib/connect.c b/lib/connect.c
index 04e3d234b..28783445e 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -31,6 +31,7 @@
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
+#include <netinet/tcp.h> /* for TCP_NODELAY */
#endif
#include <sys/ioctl.h>
#ifdef HAVE_UNISTD_H
@@ -476,6 +477,23 @@ CURLcode Curl_is_connected(struct connectdata *conn,
return CURLE_OK;
}
+static void Curl_setNoDelay(struct connectdata *conn,
+ curl_socket_t sockfd,
+ int ip)
+{
+#ifdef TCP_NODELAY
+ struct SessionHandle *data= conn->data;
+ socklen_t onoff = (socklen_t) data->tcp_nodelay;
+ infof(data,"Setting TCP_NODELAY for IPv%d\n", ip);
+ if(setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &onoff, sizeof(onoff)) < 0)
+ infof(data, "Could not set TCP_NODELAY: %s\n",
+ Curl_strerror(conn, Curl_ourerrno()));
+#else
+ (void)conn;
+ (void)sockfd;
+ (void)ip;
+#endif
+}
/*
* TCP connect to the given host with timeout, proxy or remote doesn't matter.
@@ -554,6 +572,9 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sockfd == CURL_SOCKET_BAD)
continue;
+
+ else if(data->tcp_nodelay)
+ Curl_setNoDelay(conn, sockfd, 6);
#else
/*
* Connecting with old style IPv4-only support
@@ -573,6 +594,9 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
return CURLE_COULDNT_CONNECT; /* big time error */
}
+ else if(data->tcp_nodelay)
+ Curl_setNoDelay(conn, sockfd, 4);
+
/* nasty address work before connect can be made */
memset((char *) &serv_addr, '\0', sizeof(serv_addr));
memcpy((char *)&(serv_addr.sin_addr),
diff --git a/lib/url.c b/lib/url.c
index f7b7cc378..bebf51df1 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -1303,6 +1303,14 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...)
data->set.max_filesize = va_arg(param, curl_off_t);
break;
+ case CURLOPT_TCP_NODELAY:
+ /*
+ * Enable or disable TCP_NODELAY, which will disable/enable the Nagle
+ * algorithm
+ */
+ data->tcp_nodelay = va_arg(param, long);
+ break;
+
default:
/* unknown tag and its companion, just ignore: */
return CURLE_FAILED_INIT; /* correct this */
diff --git a/lib/urldata.h b/lib/urldata.h
index e9bea7e44..fbb6c498f 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -908,6 +908,9 @@ struct SessionHandle {
#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
ENGINE* engine;
#endif /* USE_SSLEAY */
+
+ /* This tells CreateConnection() whether to enable TCP_NODELAY or not */
+ int tcp_nodelay;
};
#define LIBCURL_NAME "libcurl"