--- a/src/main.c	2007-12-05 12:39:07.000000000 +0100
+++ b/src/main.c	2007-12-10 13:53:02.000000000 +0100
@@ -480,6 +480,7 @@ struct Configurable {
   char *libcurl; /* output libcurl code to this file name */
   bool raw;
   bool post301;
+  bool nokeepalive;
   struct OutStruct *outs;
 };
 
@@ -687,6 +688,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 activation of SO_KEEPALIVE on TCP socket",
     "    --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",
@@ -1430,6 +1432,26 @@ static int ftpcccmethod(struct Configura
   return CURLFTPSSL_CCC_PASSIVE;
 }
 
+
+static int set_so_keepalive(void *clientp, curl_socket_t curlfd, curlsocktype purpose)
+{
+  int data = 1;
+
+  switch (purpose) {
+  case CURLSOCKTYPE_IPCXN:
+    if (setsockopt(curlfd, SOL_SOCKET, SO_KEEPALIVE, &data, sizeof(data)) < 0) {
+      warnf(clientp, "/!\\ Could not set SO_KEEPALIVE /!\\\n");
+      return 1;
+    }
+    break;
+  default:
+    warnf(clientp, "/!\\ Unknown CURLOPT_SOCKOPTFUNCTION purpose /!\\\n");
+  }
+
+  return 0;
+}
+
+
 static ParameterError getparameter(char *flag, /* f or -long-flag */
                                    char *nextarg, /* NULL if unset */
                                    bool *usedarg, /* set to TRUE if the arg
@@ -1516,6 +1538,7 @@ static ParameterError getparameter(char 
     {"$z", "libcurl",    TRUE},
     {"$#", "raw",        FALSE},
     {"$0", "post301",    FALSE},
+    {"$1", "no-keep-alive",    FALSE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -1971,6 +1994,9 @@ static ParameterError getparameter(char 
       case '0': /* --post301 */
         config->post301 ^= TRUE;
         break;
+      case '1': /* --no-keep-alive */
+        config->nokeepalive ^= TRUE;
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -3521,6 +3547,7 @@ static void dumpeasycode(struct Configur
   curl_slist_free_all(easycode);
 }
 
+
 static int
 operate(struct Configurable *config, int argc, argv_item_t argv[])
 {
@@ -4408,6 +4435,8 @@ operate(struct Configurable *config, int
 
         /* curl 7.17.1 */
         my_setopt(curl, CURLOPT_POST301, config->post301);
+        if (!config->nokeepalive)
+          my_setopt(curl, CURLOPT_SOCKOPTFUNCTION, set_so_keepalive);
 
         retry_numretries = config->req_retry;
 

