diff --git a/CHANGES b/CHANGES
index 95c81e998a8d23aba5728b0c4e91696498cc49ee..6ce94b139b5a2f0e0a7f28e9f8d7190ed82a29f3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,10 @@
                                   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)
 - Andrew Moise filed bug report #1847501
   (http://curl.haxx.se/bug/view.cgi?id=1847501) and pointed out a memcpy()
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index 6dbe307c16c7be65eab3c7574faf10f260b6ca50..a1f1d7a38933ec76f2f2e11d2436b98c522cd9bd 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -1,7 +1,7 @@
 Curl and libcurl 7.17.2
 
  Public curl releases:         103
- Command line options:         122
+ Command line options:         123
  curl_easy_setopt() options:   148
  Public functions in libcurl:  55
  Public web site mirrors:      42
@@ -12,6 +12,7 @@ This release includes the following changes:
  
  o --data-urlencode was added
  o CURLOPT_PROXY_TRANSFER_MODE was added
+ o --no-keep-alive was added
 
 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,
  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)
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 85f8b014f42394ec0d2e9bec93d3020090e3e7f1..dc75fbbbd69d799982c7e5f601f074e5d9d92911 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -1,4 +1,6 @@
 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 - 
diff --git a/docs/curl.1 b/docs/curl.1
index e121a91355109d7fda80185ed43ca470169c1c55..45dff0b835a6ac86782c12bdae1fed849aff8675 100644
--- a/docs/curl.1
+++ b/docs/curl.1
@@ -819,6 +819,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
+curl enables them.
+
+If this option is used twice, the second will again enable keep-alive.
 .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
diff --git a/src/main.c b/src/main.c
index c3a830bc62388c9c05c7ed84ed4622311a076c51..585d98b0c2e909c9283a1aedadbfb664d2e15289 100644
--- a/src/main.c
+++ b/src/main.c
@@ -481,6 +481,7 @@ struct Configurable {
   char *libcurl; /* output libcurl code to this file name */
   bool raw;
   bool post301;
+  bool nokeepalive;
   struct OutStruct *outs;
 };
 
@@ -689,6 +690,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-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",
@@ -1432,6 +1434,30 @@ static int ftpcccmethod(struct Configurable *config, char *str)
   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 */
                                    char *nextarg, /* NULL if unset */
                                    bool *usedarg, /* set to TRUE if the arg
@@ -1518,6 +1544,7 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
     {"$z", "libcurl",    TRUE},
     {"$#", "raw",        FALSE},
     {"$0", "post301",    FALSE},
+    {"$1", "no-keep-alive",    FALSE},
 
     {"0", "http1.0",     FALSE},
     {"1", "tlsv1",       FALSE},
@@ -1974,6 +2001,9 @@ static ParameterError getparameter(char *flag, /* f or -long-flag */
       case '0': /* --post301 */
         config->post301 ^= TRUE;
         break;
+      case '1': /* --no-keep-alive */
+        config->nokeepalive ^= TRUE;
+        break;
       }
       break;
     case '#': /* --progress-bar */
@@ -3604,6 +3634,7 @@ static void dumpeasycode(struct Configurable *config)
   curl_slist_free_all(easycode);
 }
 
+
 static int
 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 */
         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;