--- tl.orig/nanohttp/nanohttp-socket.c
+++ tl/nanohttp/nanohttp-socket.c
@@ -176,6 +176,10 @@
 {
   struct sockaddr_in address;
   struct hostent *host;
+  fd_set fds;
+  struct timeval timeout;
+  int ret;
+
 #ifdef HAVE_GETHOSTBYNAME_R
   struct hostent hostbuf;
   char gethostbyname_buf[1024];
@@ -207,10 +211,23 @@
   log_verbose4("Opening %s://%s:%i", ssl ? "https" : "http", hostname, port);
 
   /* connect to the server */
-  if (connect(dsock->sock, (struct sockaddr *) &address, sizeof(address)) !=
-      0)
-    return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT,
+  if (fcntl(dsock->sock, F_SETFL, O_NONBLOCK) == -1
+  || connect(dsock->sock, (struct sockaddr *) &address, sizeof(address)) != 0)
+  {
+    if(errno != EINPROGRESS)
+      return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT,
                       "Socket error (%s)", strerror(errno));
+  }
+
+  FD_ZERO(&fds);
+  FD_SET(dsock->sock, &fds);
+  timeout.tv_sec = httpd_get_timeout();
+  timeout.tv_usec = 0;
+  ret = select(dsock->sock + 1, NULL, &fds, NULL, &timeout);
+  if(ret == 0)
+    return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "Socket timeout");
+  if(ret == -1)
+    return herror_new("hsocket_open", HSOCKET_ERROR_CONNECT, "select error");
 
   if (ssl)
   {
