Gilles Blanc made the curl tool enable SO_KEEPALIVE for the connections and

added the --no-keep-alive option that can disable that on demand.
This commit is contained in:
Daniel Stenberg 2007-12-12 11:22:15 +00:00
parent 92eae30f4d
commit dc24540ed1
5 changed files with 51 additions and 3 deletions

View File

@ -7,6 +7,10 @@
Changelog Changelog
Daniel S (12 Dec 2007)
- Gilles Blanc made the curl tool enable SO_KEEPALIVE for the connections and
added the --no-keep-alive option that can disable that on demand.
Daniel S (9 Dec 2007) Daniel S (9 Dec 2007)
- Andrew Moise filed bug report #1847501 - Andrew Moise filed bug report #1847501
(http://curl.haxx.se/bug/view.cgi?id=1847501) and pointed out a memcpy() (http://curl.haxx.se/bug/view.cgi?id=1847501) and pointed out a memcpy()

View File

@ -1,7 +1,7 @@
Curl and libcurl 7.17.2 Curl and libcurl 7.17.2
Public curl releases: 103 Public curl releases: 103
Command line options: 122 Command line options: 123
curl_easy_setopt() options: 148 curl_easy_setopt() options: 148
Public functions in libcurl: 55 Public functions in libcurl: 55
Public web site mirrors: 42 Public web site mirrors: 42
@ -12,6 +12,7 @@ This release includes the following changes:
o --data-urlencode was added o --data-urlencode was added
o CURLOPT_PROXY_TRANSFER_MODE was added o CURLOPT_PROXY_TRANSFER_MODE was added
o --no-keep-alive was added
This release includes the following bugfixes: This release includes the following bugfixes:
@ -53,6 +54,7 @@ advice from friends like these:
Dan Fandrich, Gisle Vanem, Toby Peterson, Yang Tse, Daniel Black, Dan Fandrich, Gisle Vanem, Toby Peterson, Yang Tse, Daniel Black,
Robin Johnson, Michal Marek, Ates Goral, Andres Garcia, Rob Crittenden, Robin Johnson, Michal Marek, Ates Goral, Andres Garcia, Rob Crittenden,
Emil Romanus, Alessandro Vesely, Ray Pekowski, Spacen Jasset, Andrew Moise Emil Romanus, Alessandro Vesely, Ray Pekowski, Spacen Jasset, Andrew Moise,
Gilles Blanc
Thanks! (and sorry if I forgot to mention someone) Thanks! (and sorry if I forgot to mention someone)

View File

@ -1,4 +1,6 @@
To be addressed before 7.17.2 (planned release: December 2007) To be addressed before 7.17.2 (planned release: December 2007)
============================= =============================
108 - 108 - socklen_t usage in curl/curl.h for systems without it
109 -

View File

@ -819,6 +819,11 @@ will output the data in chunks, not necessarily exactly when the data arrives.
Using this option will disable that buffering. Using this option will disable that buffering.
If this option is used twice, the second will again switch on buffering. If this option is used twice, the second will again switch on buffering.
.IP "--no-keep-alive"
Disables the use of keep-alive messages on the TCP connection, as by default
curl enables them.
If this option is used twice, the second will again enable keep-alive.
.IP "--no-sessionid" .IP "--no-sessionid"
(SSL) Disable curl's use of SSL session-ID caching. By default all transfers (SSL) Disable curl's use of SSL session-ID caching. By default all transfers
are done using the cache. Note that while nothing ever should get hurt by are done using the cache. Note that while nothing ever should get hurt by

View File

@ -481,6 +481,7 @@ struct Configurable {
char *libcurl; /* output libcurl code to this file name */ char *libcurl; /* output libcurl code to this file name */
bool raw; bool raw;
bool post301; bool post301;
bool nokeepalive;
struct OutStruct *outs; struct OutStruct *outs;
}; };
@ -689,6 +690,7 @@ static void help(void)
" --netrc-optional Use either .netrc or URL; overrides -n", " --netrc-optional Use either .netrc or URL; overrides -n",
" --ntlm Use HTTP NTLM authentication (H)", " --ntlm Use HTTP NTLM authentication (H)",
" -N/--no-buffer Disable buffering of the output stream", " -N/--no-buffer Disable buffering of the output stream",
" --no-keep-alive Disable keep-alive use on the connection",
" --no-sessionid Disable SSL session-ID reusing (SSL)", " --no-sessionid Disable SSL session-ID reusing (SSL)",
" -o/--output <file> Write output to <file> instead of stdout", " -o/--output <file> Write output to <file> instead of stdout",
" -O/--remote-name Write output to a file named as the remote file", " -O/--remote-name Write output to a file named as the remote file",
@ -1432,6 +1434,30 @@ static int ftpcccmethod(struct Configurable *config, char *str)
return CURLFTPSSL_CCC_PASSIVE; return CURLFTPSSL_CCC_PASSIVE;
} }
static int set_so_keepalive(void *clientp, curl_socket_t curlfd,
curlsocktype purpose)
{
struct Configurable *config = (struct Configurable *)clientp;
int data = !config->nokeepalive;
switch (purpose) {
case CURLSOCKTYPE_IPCXN:
/* setsockopt()'s 5th argument is a 'socklen_t' type in POSIX, but windows
and other pre-POSIX systems use 'int' here! */
if (setsockopt(curlfd, SOL_SOCKET, SO_KEEPALIVE, &data, sizeof(data)) < 0) {
warnf(clientp, "Could not set SO_KEEPALIVE!\n");
return 1;
}
break;
default:
break;
}
return 0;
}
static ParameterError getparameter(char *flag, /* f or -long-flag */ static ParameterError getparameter(char *flag, /* f or -long-flag */
char *nextarg, /* NULL if unset */ char *nextarg, /* NULL if unset */
bool *usedarg, /* set to TRUE if the arg bool *usedarg, /* set to TRUE if the arg
@ -1518,6 +1544,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
{"$z", "libcurl", TRUE}, {"$z", "libcurl", TRUE},
{"$#", "raw", FALSE}, {"$#", "raw", FALSE},
{"$0", "post301", FALSE}, {"$0", "post301", FALSE},
{"$1", "no-keep-alive", FALSE},
{"0", "http1.0", FALSE}, {"0", "http1.0", FALSE},
{"1", "tlsv1", FALSE}, {"1", "tlsv1", FALSE},
@ -1974,6 +2001,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
case '0': /* --post301 */ case '0': /* --post301 */
config->post301 ^= TRUE; config->post301 ^= TRUE;
break; break;
case '1': /* --no-keep-alive */
config->nokeepalive ^= TRUE;
break;
} }
break; break;
case '#': /* --progress-bar */ case '#': /* --progress-bar */
@ -3604,6 +3634,7 @@ static void dumpeasycode(struct Configurable *config)
curl_slist_free_all(easycode); curl_slist_free_all(easycode);
} }
static int static int
operate(struct Configurable *config, int argc, argv_item_t argv[]) operate(struct Configurable *config, int argc, argv_item_t argv[])
{ {
@ -4496,6 +4527,10 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
/* curl 7.17.1 */ /* curl 7.17.1 */
my_setopt(curl, CURLOPT_POST301, config->post301); my_setopt(curl, CURLOPT_POST301, config->post301);
if (!config->nokeepalive) {
my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, set_so_keepalive);
my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
}
retry_numretries = config->req_retry; retry_numretries = config->req_retry;