tcp-nodelay patch by Joe Halpin

This commit is contained in:
Daniel Stenberg 2004-03-25 13:37:18 +00:00
parent 189c2f4989
commit bb3d6e8552
7 changed files with 70 additions and 1 deletions

View file

@ -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),

View file

@ -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 */

View file

@ -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"