]> granicus.if.org Git - curl/commitdiff
Eric Landes provided the patch (edited by me) that introduces the
authorDaniel Stenberg <daniel@haxx.se>
Sat, 12 Jan 2008 22:10:53 +0000 (22:10 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 12 Jan 2008 22:10:53 +0000 (22:10 +0000)
--keepalive-time to curl to set the keepalive probe interval. I also took
the opportunity to rename the recently added no-keep-alive option to
no-keepalive to keep a consistent naming and to avoid getting two dashes in
these option names. Eric also provided an update to the man page for the new
option.

CHANGES
RELEASE-NOTES
TODO-RELEASE
docs/curl.1
src/main.c

diff --git a/CHANGES b/CHANGES
index 203d9463470a71cd99d3adbedde6fd8f271a7531..b2493802273c2c0525ae1c1b36ae45e071f88620 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,14 @@
 
                                   Changelog
 
+Daniel S (12 Jan 2008)
+- Eric Landes provided the patch (edited by me) that introduces the
+  --keepalive-time to curl to set the keepalive probe interval. I also took
+  the opportunity to rename the recently added no-keep-alive option to
+  no-keepalive to keep a consistent naming and to avoid getting two dashes in
+  these option names. Eric also provided an update to the man page for the new
+  option.
+
 Daniel S (11 Jan 2008)
 - Daniel Egger made CURLOPT_RANGE work on file:// URLs the very same way it
   already worked for FTP:// URLs.
index 49f540fe97ea3afec36950b900e6b8007c51bfa0..b1d41c1311f9b732c12821fc157d85bb92b5f515 100644 (file)
@@ -1,7 +1,7 @@
 Curl and libcurl 7.18.0
 
  Public curl releases:         103
- Command line options:         125
+ Command line options:         126
  curl_easy_setopt() options:   150
  Public functions in libcurl:  56
  Public web site mirrors:      42
@@ -12,12 +12,13 @@ This release includes the following changes:
  
  o --data-urlencode
  o CURLOPT_PROXY_TRANSFER_MODE
- o --no-keep-alive - now curl does connections with keep-alive enabled by
+ o --no-keepalive - now curl does connections with keep-alive enabled by
    default
  o --socks4a added (proxy type CURLPROXY_SOCKS4A for libcurl)
  o --socks5-hostname added (CURLPROXY_SOCKS5_HOSTNAME for libcurl)
  o curl_easy_pause()
  o CURLOPT_SEEKFUNCTION and CURLOPT_SEEKDATA
+ o --keepalive-time
 
 This release includes the following bugfixes:
 
@@ -72,6 +73,6 @@ advice from friends like these:
  Emil Romanus, Alessandro Vesely, Ray Pekowski, Spacen Jasset, Andrew Moise,
  Gilles Blanc, David Wright, Vikram Saxena, Mateusz Loskot, Gary Maxwell,
  Dmitry Kurochkin, Mohun Biswas, Richard Atterer, Maxim Perenesenko,
- Daniel Egger, Jeff Johnson, Nikitinskit Dmitriy, Georg Lippitsch
+ Daniel Egger, Jeff Johnson, Nikitinskit Dmitriy, Georg Lippitsch, Eric Landes
  
         Thanks! (and sorry if I forgot to mention someone)
index cc6e48894e441609e2ee72c996b64cabefa3716b..278e1f87365bcd291d531c26f7778d48a801d51c 100644 (file)
@@ -4,9 +4,6 @@ To be addressed before 7.18.0 (planned release: January 2008)
 115 - Cleanup debugging messages in test harness, introduced for new minimum
       SSH version support for SCP, SFTP and SOCKS tests
       
-117 - Eric Landes patch for introducing the --tcp-keep* options
-      http://curl.haxx.se/mail/lib-2008-01/0038.html (review, consider)
-
 Less likely to go in 7.18.0
 ===========================
 
index 0babaaaf41c6527f7e4454a7f59046eb034d3b82..91aeb0024233f015c4c4febee594fb6d6c8d1d30 100644 (file)
@@ -612,6 +612,14 @@ See this online resource for further details:
 \fBhttp://curl.haxx.se/docs/sslcerts.html\fP
 
 If this option is used twice, the second time will again disable it.
+.IP "--keepalive-time <seconds>"
+This option sets the time a connection needs to remain idle before sending
+keepalive probes and the time between individual keepalive probes. It is
+currently effective on operating systems offering the TCP_KEEPIDLE and
+TCP_KEEPINTVL socket options (meaning Linux, recent AIX, HP-UX and more). This
+option has no effect if \fI--no-keepalive\fP is used. (Added in 7.18.0)
+
+If this option is used multiple times, the last occurrence sets the amount.
 .IP "--key <key>"
 (SSL/SSH) Private key file name. Allows you to provide your private key in this
 separate file.
@@ -820,11 +828,11 @@ will output the data in chunks, not necessarily exactly when the data arrives.
 Using this option will disable that 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
+.IP "--no-keepalive"
+Disables the use of keepalive messages on the TCP connection, as by default
 curl enables them.
 
-If this option is used twice, the second will again enable keep-alive.
+If this option is used twice, the second will again enable keepalive.
 .IP "--no-sessionid"
 (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
index 7801c345f5480fda173063215a0e289699d3e9d8..55a75bb3fb80a85c34ca8dbd94f0008ffaa7a277 100644 (file)
 #endif
 #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
 
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h> /* for IPPROTO_TCP */
+#endif
+#ifdef HAVE_NETINET_TCP_H
+#include <netinet/tcp.h> /* for TCP_KEEPIDLE, TCP_KEEPINTVL */
+#endif
+
 /* The last #include file should be: */
 #ifdef CURLDEBUG
 #ifndef CURLTOOLDEBUG
@@ -486,7 +493,9 @@ struct Configurable {
   char *libcurl; /* output libcurl code to this file name */
   bool raw;
   bool post301;
-  bool nokeepalive;
+  bool nokeepalive; /* for keepalive needs */
+  long alivetime;
+
   struct OutStruct *outs;
 };
 
@@ -679,6 +688,7 @@ static void help(void)
     " -I/--head          Show document info only",
     " -j/--junk-session-cookies Ignore session cookies read from file (H)",
     "    --interface <interface> Specify network interface/address to use",
+    "    --keepalive-time <seconds> Interval between keepalive probes",
     "    --krb <level>   Enable kerberos with specified security level (F)",
     " -k/--insecure      Allow connections to SSL sites without certs (H)",
     " -K/--config        Specify which config file to read",
@@ -697,7 +707,7 @@ static void help(void)
     "    --netrc-optional Use either .netrc or URL; overrides -n",
     "    --ntlm          Use HTTP NTLM authentication (H)",
     " -N/--no-buffer     Disable buffering of the output stream",
-    "    --no-keep-alive Disable keep-alive use on the connection",
+    "    --no-keepalive  Disable keepalive use on the connection",
     "    --no-sessionid  Disable SSL session-ID reusing (SSL)",
     " -o/--output <file> Write output to <file> instead of stdout",
     " -O/--remote-name   Write output to a file named as the remote file",
@@ -1444,11 +1454,13 @@ static int ftpcccmethod(struct Configurable *config, char *str)
 }
 
 
-static int set_so_keepalive(void *clientp, curl_socket_t curlfd,
-                            curlsocktype purpose)
+static int sockoptcallback(void *clientp, curl_socket_t curlfd,
+                           curlsocktype purpose)
 {
   struct Configurable *config = (struct Configurable *)clientp;
-  int onoff = config->nokeepalive ? 0 : 1;
+  int onoff = 1; /* this callback is only used if we ask for keepalives on the
+                    connection */
+  long keepidle = config->alivetime;
 
   switch (purpose) {
   case CURLSOCKTYPE_IPCXN:
@@ -1459,6 +1471,28 @@ static int set_so_keepalive(void *clientp, curl_socket_t curlfd,
       warnf(clientp, "Could not set SO_KEEPALIVE!\n");
       return 0;
     }
+    else {
+      if (config->alivetime) {
+#ifdef TCP_KEEPIDLE
+        if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&keepidle,
+                      sizeof(keepidle)) < 0) {
+          /* don't abort operation, just issue a warning */
+          SET_SOCKERRNO(0);
+          warnf(clientp, "Could not set TCP_KEEPIDLE!\n");
+          return 0;
+        }
+#endif
+#ifdef TCP_KEEPINTVL
+        if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&keepidle,
+                      sizeof(keepidle)) < 0) {
+          /* don't abort operation, just issue a warning */
+          SET_SOCKERRNO(0);
+          warnf(clientp, "Could not set TCP_KEEPINTVL!\n");
+          return 0;
+        }
+#endif
+      }
+    }
     break;
   default:
     break;
@@ -1555,8 +1589,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"$z", "libcurl",    TRUE},
     {"$#", "raw",        FALSE},
     {"$0", "post301",    FALSE},
-    {"$1", "no-keep-alive",    FALSE},
-    {"$2", "socks5-hostname",    TRUE},
+    {"$1", "no-keepalive",   FALSE},
+    {"$2", "socks5-hostname", TRUE},
+    {"$3", "keepalive-time",  TRUE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -2024,9 +2059,13 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
       case '0': /* --post301 */
         config->post301 ^= TRUE;
         break;
-      case '1': /* --no-keep-alive */
+      case '1': /* --no-keepalive */
         config->nokeepalive ^= TRUE;
         break;
+      case '3': /* --keepalive-time */
+        if(str2num(&config->alivetime, nextarg))
+          return PARAM_BAD_NUMERIC;
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -4590,7 +4629,7 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
         /* curl 7.17.1 */
         my_setopt(curl, CURLOPT_POST301, config->post301);
         if (!config->nokeepalive) {
-          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, set_so_keepalive);
+          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockoptcallback);
           my_setopt(curl, CURLOPT_SOCKOPTDATA, config);
         }