From bb3d6e8552f428bd0c2624854403d36ab3cf163d Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 25 Mar 2004 13:37:18 +0000 Subject: tcp-nodelay patch by Joe Halpin --- lib/connect.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'lib/connect.c') 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 +#include /* for TCP_NODELAY */ #endif #include #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), -- cgit v1.2.3