--- _CVS_cURL_orig_jan/curl/src/main.c	2008-01-12 16:54:02.000000000 +0100
+++ _CVS_cURL_modif_jan_v3/curl/src/main.c	2008-01-12 17:22:53.000000000 +0100
@@ -104,6 +104,15 @@
 #endif
 #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
 
+#ifndef WIN32
+#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
+#endif
+
 /* The last #include file should be: */
 #ifdef CURLDEBUG
 #ifndef CURLTOOLDEBUG
@@ -486,7 +495,10 @@
   char *libcurl; /* output libcurl code to this file name */
   bool raw;
   bool post301;
-  bool nokeepalive;
+
+  bool nokeepalive; /* for keepalive needs */
+  long tcp_keepidle;
+
   struct OutStruct *outs;
 };
 
@@ -725,6 +737,7 @@
     "    --socks5-hostname <host[:port]> SOCKS5 proxy, pass name instead of IP",
     "    --socks5 <host[:port]> SOCKS5 proxy on given host + port",
     "    --stderr <file> Where to redirect stderr. - means stdout",
+    "    --tcp-keepidle <seconds> Time before sending keepalive probes",
     " -t/--telnet-option <OPT=val> Set telnet option",
     "    --trace <file>  Write a debug trace to the given file",
     "    --trace-ascii <file> Like --trace but without the hex output",
@@ -1444,11 +1457,12 @@
 }
 
 
-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;
+  long keepidle = config->tcp_keepidle;
 
   switch (purpose) {
   case CURLSOCKTYPE_IPCXN:
@@ -1459,6 +1473,28 @@
       warnf(clientp, "Could not set SO_KEEPALIVE!\n");
       return 0;
     }
+    else {
+      if (config->tcp_keepidle>0) {
+#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;
@@ -1557,6 +1593,7 @@
     {"$0", "post301",    FALSE},
     {"$1", "no-keep-alive",    FALSE},
     {"$2", "socks5-hostname",    TRUE},
+    {"$3", "tcp-keepidle",    TRUE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -2027,6 +2064,10 @@
       case '1': /* --no-keep-alive */
         config->nokeepalive ^= TRUE;
         break;
+      case '3': /* --tcp-keepidle */
+        if(str2num(&config->tcp_keepidle, nextarg))
+          return PARAM_BAD_NUMERIC;
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -4590,7 +4631,7 @@
         /* 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);
         }
 
--- _CVS_cURL_orig_jan/curl/docs/curl.1	2008-01-12 16:53:20.000000000 +0100
+++ _CVS_cURL_modif_jan_v3/curl//docs/curl.1	2008-01-12 17:52:05.000000000 +0100
@@ -1110,6 +1110,14 @@
 you're using a shell with decent redirecting capabilities.
 
 If this option is used several times, the last one will be used.
+.IP "--tcp-keepidle <seconds>"
+This option permits to change the time a connection needs to remain
+idle before sending keepalive probes and the time between individual
+keepalive probes. It is currently effective on OS defining TCP_KEEPIDLE and
+TCP_KEEPINTVL socket options (Linux, recent AIX and HP-UX, ...). This option
+has not effect if \fI--nokeepalive\fP is used.
+
+If this option is used multiple times, the last occurrence decide the amount.
 .IP "--tcp-nodelay"
 Turn on the TCP_NODELAY option. See the \fIcurl_easy_setopt(3)\fP man page for
 details about this option. (Added in 7.11.2)

