diff -urNp curl-7.18.1-orig/lib/connect.c curl-7.18.1/lib/connect.c
--- curl-7.18.1-orig/lib/connect.c	2008-02-07 23:25:04.000000000 +0100
+++ curl-7.18.1/lib/connect.c	2008-04-12 04:13:36.000000000 +0200
@@ -235,17 +235,20 @@ int Curl_nonblock(curl_socket_t sockfd, 
  * number if milliseconds. It returns:
  * 0    fine connect
  * -1   select() error
+ * -2   select() aborted by callback
  * 1    select() timeout
  * 2    select() returned with an error condition fd_set
  */
 
 #define WAITCONN_CONNECTED     0
 #define WAITCONN_SELECT_ERROR -1
+#define WAITCONN_ABORTED      -2
 #define WAITCONN_TIMEOUT       1
 #define WAITCONN_FDSET_ERROR   2
 
 static
-int waitconnect(curl_socket_t sockfd, /* socket */
+int waitconnect(struct connectdata *conn,
+                curl_socket_t sockfd, /* socket */
                 long timeout_msec)
 {
   int rc;
@@ -257,11 +260,15 @@ int waitconnect(curl_socket_t sockfd, /*
 #endif
 
   /* now select() until we get connect or timeout */
-  rc = Curl_socket_ready(CURL_SOCKET_BAD, sockfd, (int)timeout_msec);
+  rc = Curl_socket_ready(conn, CURL_SOCKET_BAD, sockfd, (int)timeout_msec);
   if(-1 == rc)
     /* error, no connect here, try next */
     return WAITCONN_SELECT_ERROR;
 
+  else if(-2 == rc)
+    /* aborted by callback */
+    return WAITCONN_ABORTED;
+
   else if(0 == rc)
     /* timeout, no connect today */
     return WAITCONN_TIMEOUT;
@@ -623,7 +630,7 @@ CURLcode Curl_is_connected(struct connec
   Curl_expire(data, allow);
 
   /* check for connect without timeout as we want to return immediately */
-  rc = waitconnect(sockfd, 0);
+  rc = waitconnect(conn, sockfd, 0);
 
   if(WAITCONN_CONNECTED == rc) {
     int error;
@@ -814,7 +821,7 @@ singleipconnect(struct connectdata *conn
        */
     case EAGAIN:
 #endif
-      rc = waitconnect(sockfd, timeout_ms);
+      rc = waitconnect(conn, sockfd, timeout_ms);
       break;
     default:
       /* unknown error, fallthrough and try another address! */
@@ -843,6 +850,8 @@ singleipconnect(struct connectdata *conn
   }
   else if(WAITCONN_TIMEOUT == rc)
     infof(data, "Timeout\n");
+  else if(WAITCONN_ABORTED == rc)
+    infof(data, "interrupted, aborting\n");
   else {
     data->state.os_errno = error;
     infof(data, "%s\n", Curl_strerror(conn, error));
diff -urNp curl-7.18.1-orig/lib/ftp.c curl-7.18.1/lib/ftp.c
--- curl-7.18.1-orig/lib/ftp.c	2008-02-07 23:25:04.000000000 +0100
+++ curl-7.18.1/lib/ftp.c	2008-04-12 04:13:36.000000000 +0200
@@ -310,11 +310,13 @@ static CURLcode AllowServerConnect(struc
     return CURLE_OPERATION_TIMEDOUT;
   }
 
-  switch (Curl_socket_ready(sock, CURL_SOCKET_BAD, (int)timeout_ms)) {
+  switch (Curl_socket_ready(conn, sock, CURL_SOCKET_BAD, (int)timeout_ms)) {
   case -1: /* error */
     /* let's die here */
     failf(data, "Error while waiting for server connect");
     return CURLE_FTP_PORT_FAILED;
+  case -2: /* aborted by callback */
+    return CURLE_ABORTED_BY_CALLBACK;
   case 0:  /* timeout */
     /* let's die here */
     failf(data, "Timeout while waiting for server connect");
@@ -672,12 +674,15 @@ CURLcode Curl_GetFTPResponse(ssize_t *nr
        */
     }
     else {
-      switch (Curl_socket_ready(sockfd, CURL_SOCKET_BAD, (int)interval_ms)) {
+      switch (Curl_socket_ready(conn, sockfd, CURL_SOCKET_BAD, (int)interval_ms)) {
       case -1: /* select() error, stop reading */
         failf(data, "FTP response aborted due to select/poll error: %d",
               SOCKERRNO);
         return CURLE_RECV_ERROR;
 
+      case -2: /* aborted by callback */
+        return CURLE_ABORTED_BY_CALLBACK;
+
       case 0: /* timeout */
         if(Curl_pgrsUpdate(conn))
           return CURLE_ABORTED_BY_CALLBACK;
@@ -2935,7 +2940,8 @@ static CURLcode ftp_multi_statemach(stru
     return CURLE_OPERATION_TIMEDOUT;
   }
 
-  rc = Curl_socket_ready(ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
+  rc = Curl_socket_ready(conn,
+                         ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
                          ftpc->sendleft?sock:CURL_SOCKET_BAD, /* writing */
                          0);
 
@@ -2968,7 +2974,8 @@ static CURLcode ftp_easy_statemach(struc
       return CURLE_OPERATION_TIMEDOUT; /* already too little time */
     }
 
-    rc = Curl_socket_ready(ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
+    rc = Curl_socket_ready(conn,
+                           ftpc->sendleft?CURL_SOCKET_BAD:sock, /* reading */
                            ftpc->sendleft?sock:CURL_SOCKET_BAD, /* writing */
                            (int)timeout_ms);
 
@@ -2976,6 +2983,8 @@ static CURLcode ftp_easy_statemach(struc
       failf(data, "select/poll error");
       return CURLE_OUT_OF_MEMORY;
     }
+    else if(rc == -2)
+      return CURLE_ABORTED_BY_CALLBACK;
     else if(rc == 0) {
       result = CURLE_OPERATION_TIMEDOUT;
       break;
diff -urNp curl-7.18.1-orig/lib/gtls.c curl-7.18.1/lib/gtls.c
--- curl-7.18.1-orig/lib/gtls.c	2008-02-26 12:45:17.000000000 +0100
+++ curl-7.18.1/lib/gtls.c	2008-04-12 04:13:36.000000000 +0200
@@ -165,7 +165,7 @@ static CURLcode handshake(struct connect
         return CURLE_OPERATION_TIMEDOUT;
       }
 
-      rc = Curl_socket_ready(conn->sock[sockindex],
+      rc = Curl_socket_ready(conn, conn->sock[sockindex],
                        conn->sock[sockindex], (int)timeout_ms);
       if(rc > 0)
         /* reabable or writable, go loop*/
@@ -175,6 +175,8 @@ static CURLcode handshake(struct connect
         failf(data, "SSL connection timeout");
         return CURLE_OPERATION_TIMEDOUT;
       }
+      else if(-2 == rc)
+        return CURLE_ABORTED_BY_CALLBACK;
       else {
         /* anything that gets here is fatally bad */
         failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
@@ -609,7 +611,7 @@ int Curl_gtls_shutdown(struct connectdat
 
   if(conn->ssl[sockindex].session) {
     while(!done) {
-      int what = Curl_socket_ready(conn->sock[sockindex],
+      int what = Curl_socket_ready(conn, conn->sock[sockindex],
                              CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
       if(what > 0) {
         /* Something to read, let's do it and hope that it is the close
@@ -638,6 +640,10 @@ int Curl_gtls_shutdown(struct connectdat
         done = 1;
         break;
       }
+      else if(-2 == what) {
+        retval = -1;
+        done = 1;
+      }
       else {
         /* anything that gets here is fatally bad */
         failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
diff -urNp curl-7.18.1-orig/lib/hostares.c curl-7.18.1/lib/hostares.c
--- curl-7.18.1-orig/lib/hostares.c	2008-03-23 12:02:28.000000000 +0100
+++ curl-7.18.1/lib/hostares.c	2008-04-12 04:13:36.000000000 +0200
@@ -169,7 +169,7 @@ static int ares_waitperform(struct conne
   num = i;
 
   if(num)
-    nfds = Curl_poll(pfd, num, timeout_ms);
+    nfds = Curl_poll(conn, pfd, num, timeout_ms);
   else
     nfds = 0;
 
diff -urNp curl-7.18.1-orig/lib/http.c curl-7.18.1/lib/http.c
--- curl-7.18.1-orig/lib/http.c	2008-03-30 11:00:51.000000000 +0200
+++ curl-7.18.1/lib/http.c	2008-04-12 04:13:36.000000000 +0200
@@ -1231,6 +1231,7 @@ CURLcode Curl_proxyCONNECT(struct connec
 #define SELECT_OK      0
 #define SELECT_ERROR   1
 #define SELECT_TIMEOUT 2
+#define SELECT_ABORTED 3
   int error = SELECT_OK;
 
   conn->bits.proxy_connect_closed = FALSE;
@@ -1344,7 +1345,7 @@ CURLcode Curl_proxyCONNECT(struct connec
 
     /* if we're in multi-mode and we would block, return instead for a retry */
     if(Curl_if_multi == data->state.used_interface) {
-      if(0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0))
+      if(0 == Curl_socket_ready(conn, tunnelsocket, CURL_SOCKET_BAD, 0))
         /* return so we'll be called again polling-style */
         return CURLE_OK;
       else {
@@ -1392,12 +1393,15 @@ CURLcode Curl_proxyCONNECT(struct connec
         }
 
         /* loop every second at least, less if the timeout is near */
-        switch (Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD,
+        switch (Curl_socket_ready(conn, tunnelsocket, CURL_SOCKET_BAD,
                             check<1000L?(int)check:1000)) {
         case -1: /* select() error, stop reading */
           error = SELECT_ERROR;
           failf(data, "Proxy CONNECT aborted due to select/poll error");
           break;
+        case -2: /* aborted by callback */
+          error = SELECT_ABORTED;
+          break;
         case 0: /* timeout */
           break;
         default:
@@ -1602,7 +1606,8 @@ CURLcode Curl_proxyCONNECT(struct connec
       } /* while there's buffer left and loop is requested */
 
       if(error)
-        return CURLE_RECV_ERROR;
+        return (error == SELECT_ABORTED) ? CURLE_ABORTED_BY_CALLBACK :
+                                           CURLE_RECV_ERROR;
 
       if(data->info.httpproxycode != 200)
         /* Deal with the possibly already received authenticate
diff -urNp curl-7.18.1-orig/lib/qssl.c curl-7.18.1/lib/qssl.c
--- curl-7.18.1-orig/lib/qssl.c	2008-02-20 10:56:26.000000000 +0100
+++ curl-7.18.1/lib/qssl.c	2008-04-12 04:13:36.000000000 +0200
@@ -336,11 +336,15 @@ int Curl_qsossl_shutdown(struct connectd
 
   rc = 0;
 
-  what = Curl_socket_ready(conn->sock[sockindex],
+  what = Curl_socket_ready(conn, conn->sock[sockindex],
                            CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
 
   for (;;) {
-    if(what < 0) {
+    if(what == -2) {
+      rc = -1;
+      break;
+    }
+    else if(what < 0) {
       /* anything that gets here is fatally bad */
       failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
       rc = -1;
@@ -365,7 +369,7 @@ int Curl_qsossl_shutdown(struct connectd
     if(nread <= 0)
       break;
 
-    what = Curl_socket_ready(conn->sock[sockindex], CURL_SOCKET_BAD, 0);
+    what = Curl_socket_ready(conn, conn->sock[sockindex], CURL_SOCKET_BAD, 0);
   }
 
   return rc;
diff -urNp curl-7.18.1-orig/lib/select.c curl-7.18.1/lib/select.c
--- curl-7.18.1-orig/lib/select.c	2008-03-08 23:11:11.000000000 +0100
+++ curl-7.18.1/lib/select.c	2008-04-12 04:13:54.000000000 +0200
@@ -47,6 +47,7 @@
 
 #include "urldata.h"
 #include "connect.h"
+#include "progress.h"
 #include "select.h"
 
 /* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
@@ -91,9 +92,11 @@
  *
  * Return values:
  *   -1 = system call error, invalid timeout value, or interrupted
+ *   -2 = interrupted by a signal, and aborting according to the
+ *        CURLOPT_PROGRESSFUNCTION callback passed by the user
  *    0 = specified timeout has elapsed
  */
-static int wait_ms(int timeout_ms)
+static int wait_ms(struct connectdata *conn, int timeout_ms)
 {
 #if !defined(MSDOS) && !defined(USE_WINSOCK)
 #ifndef HAVE_POLL_FINE
@@ -119,6 +122,14 @@ static int wait_ms(int timeout_ms)
   pending_ms = timeout_ms;
   initial_tv = curlx_tvnow();
   do {
+    /* Extra check to honor signal interruption semantics: we are
+       possibly going to block, and it is not safe since we are not
+       blocking signals nor using ppoll()/pselect() */
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
 #if defined(HAVE_POLL_FINE)
     r = poll(NULL, 0, pending_ms);
 #else
@@ -126,18 +137,24 @@ static int wait_ms(int timeout_ms)
     pending_tv.tv_usec = (pending_ms % 1000) * 1000;
     r = select(0, NULL, NULL, NULL, &pending_tv);
 #endif /* HAVE_POLL_FINE */
+
     if(r != -1)
       break;
     error = SOCKERRNO;
     if(error && error_not_EINTR)
       break;
+
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
     pending_ms = timeout_ms - elapsed_ms;
     if(pending_ms <= 0)
       break;
   } while(r == -1);
 #endif /* USE_WINSOCK */
-  if(r)
-    r = -1;
+
   return r;
 }
 
@@ -156,11 +173,13 @@ static int wait_ms(int timeout_ms)
  *
  * Return values:
  *   -1 = system call error or fd >= FD_SETSIZE
+ *   -2 = interrupted by a signal and aborting according to the
+ *        CURLOPT_PROGRESSFUNCTION callback passed by the user
  *    0 = timeout
  *    CURL_CSELECT_IN | CURL_CSELECT_OUT | CURL_CSELECT_ERR
  */
-int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
-                      int timeout_ms)
+int Curl_socket_ready(struct connectdata *conn, curl_socket_t readfd,
+                      curl_socket_t writefd, int timeout_ms)
 {
 #ifdef HAVE_POLL_FINE
   struct pollfd pfd[2];
@@ -180,7 +199,7 @@ int Curl_socket_ready(curl_socket_t read
   int ret;
 
   if((readfd == CURL_SOCKET_BAD) && (writefd == CURL_SOCKET_BAD)) {
-    r = wait_ms(timeout_ms);
+    r = wait_ms(conn, timeout_ms);
     return r;
   }
 
@@ -215,12 +234,30 @@ int Curl_socket_ready(curl_socket_t read
       pending_ms = -1;
     else if(!timeout_ms)
       pending_ms = 0;
+
+    if(timeout_ms) {
+      /* Extra check to honor signal interruption semantics: we are
+         possibly going to block, and it is not safe since we are not
+         blocking signals nor using ppoll() */
+      if (Curl_pgrsUpdate(conn)) {
+        r = -2;
+        break;
+      }
+    }
+
     r = poll(pfd, num, pending_ms);
+
     if(r != -1)
       break;
     error = SOCKERRNO;
     if(error && error_not_EINTR)
       break;
+
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
     if(timeout_ms > 0) {
       pending_ms = timeout_ms - elapsed_ms;
       if(pending_ms <= 0)
@@ -228,10 +265,8 @@ int Curl_socket_ready(curl_socket_t read
     }
   } while(r == -1);
 
-  if(r < 0)
-    return -1;
-  if(r == 0)
-    return 0;
+  if(r <= 0)
+    return r;
 
   ret = 0;
   num = 0;
@@ -284,12 +319,30 @@ int Curl_socket_ready(curl_socket_t read
       pending_tv.tv_sec = 0;
       pending_tv.tv_usec = 0;
     }
+
+    if(timeout_ms) {
+      /* Extra check to honor signal interruption semantics: we are
+         possibly going to block, and it is not safe since we are not
+         blocking signals nor using pselect() */
+      if (Curl_pgrsUpdate(conn)) {
+        r = -2;
+        break;
+      }
+    }
+
     r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+
     if(r != -1)
       break;
     error = SOCKERRNO;
     if(error && error_not_EINTR)
       break;
+
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
     if(timeout_ms > 0) {
       pending_ms = timeout_ms - elapsed_ms;
       if(pending_ms <= 0)
@@ -297,10 +350,8 @@ int Curl_socket_ready(curl_socket_t read
     }
   } while(r == -1);
 
-  if(r < 0)
-    return -1;
-  if(r == 0)
-    return 0;
+  if(r <= 0)
+    return r;
 
   ret = 0;
   if(readfd != CURL_SOCKET_BAD) {
@@ -335,10 +386,13 @@ int Curl_socket_ready(curl_socket_t read
  *
  * Return values:
  *   -1 = system call error or fd >= FD_SETSIZE
+ *   -2 = interrupted by a signal, and aborting according to the
+ *        CURLOPT_PROGRESSFUNCTION callback passed by the user
  *    0 = timeout
  *    N = number of structures with non zero revent fields
  */
-int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
+int Curl_poll(struct connectdata *conn, struct pollfd ufds[],
+              unsigned int nfds, int timeout_ms)
 {
 #ifndef HAVE_POLL_FINE
   struct timeval pending_tv;
@@ -364,7 +418,7 @@ int Curl_poll(struct pollfd ufds[], unsi
     }
   }
   if(fds_none) {
-    r = wait_ms(timeout_ms);
+    r = wait_ms(conn, timeout_ms);
     return r;
   }
 
@@ -385,12 +439,30 @@ int Curl_poll(struct pollfd ufds[], unsi
       pending_ms = -1;
     else if(!timeout_ms)
       pending_ms = 0;
+
+    if(timeout_ms) {
+      /* Extra check to honor signal interruption semantics: we are
+         possibly going to block, and it is not safe since we are not
+         blocking signals nor using ppoll() */
+      if (Curl_pgrsUpdate(conn)) {
+        r = -2;
+        break;
+      }
+    }
+
     r = poll(ufds, nfds, pending_ms);
+
     if(r != -1)
       break;
     error = SOCKERRNO;
     if(error && error_not_EINTR)
       break;
+
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
     if(timeout_ms > 0) {
       pending_ms = timeout_ms - elapsed_ms;
       if(pending_ms <= 0)
@@ -434,12 +506,30 @@ int Curl_poll(struct pollfd ufds[], unsi
       pending_tv.tv_sec = 0;
       pending_tv.tv_usec = 0;
     }
+
+    if(timeout_ms) {
+      /* Extra check to honor signal interruption semantics: we are
+         possibly going to block, and it is not safe since we are not
+         blocking signals nor using pselect() */
+      if (Curl_pgrsUpdate(conn)) {
+        r = -2;
+        break;
+      }
+    }
+
     r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
+
     if(r != -1)
       break;
     error = SOCKERRNO;
     if(error && error_not_EINTR)
       break;
+
+    if (Curl_pgrsUpdate(conn)) {
+      r = -2;
+      break;
+    }
+
     if(timeout_ms > 0) {
       pending_ms = timeout_ms - elapsed_ms;
       if(pending_ms <= 0)
@@ -447,10 +537,8 @@ int Curl_poll(struct pollfd ufds[], unsi
     }
   } while(r == -1);
 
-  if(r < 0)
-    return -1;
-  if(r == 0)
-    return 0;
+  if(r <= 0)
+    return r;
 
   r = 0;
   for (i = 0; i < nfds; i++) {
diff -urNp curl-7.18.1-orig/lib/select.h curl-7.18.1/lib/select.h
--- curl-7.18.1-orig/lib/select.h	2008-01-23 23:20:22.000000000 +0100
+++ curl-7.18.1/lib/select.h	2008-04-12 04:13:36.000000000 +0200
@@ -83,10 +83,11 @@ struct pollfd
 #define POLLRDBAND POLLPRI
 #endif
 
-int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
-                      int timeout_ms);
+int Curl_socket_ready(struct connectdata *conn, curl_socket_t readfd,
+                      curl_socket_t writefd, int timeout_ms);
 
-int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms);
+int Curl_poll(struct connectdata *conn, struct pollfd ufds[],
+              unsigned int nfds, int timeout_ms);
 
 #ifdef TPF
 int tpf_select_libcurl(int maxfds, fd_set* reads, fd_set* writes,
diff -urNp curl-7.18.1-orig/lib/socks.c curl-7.18.1/lib/socks.c
--- curl-7.18.1-orig/lib/socks.c	2008-02-11 23:03:31.000000000 +0100
+++ curl-7.18.1/lib/socks.c	2008-04-12 04:13:36.000000000 +0200
@@ -83,7 +83,7 @@ static int blockread_all(struct connectd
       result = ~CURLE_OK;
       break;
     }
-    if(Curl_socket_ready(sockfd, CURL_SOCKET_BAD,
+    if(Curl_socket_ready(conn, sockfd, CURL_SOCKET_BAD,
                    (int)(conn_timeout - conntime)) <= 0) {
       result = ~CURLE_OK;
       break;
@@ -409,12 +409,14 @@ CURLcode Curl_SOCKS5(const char *proxy_n
   Curl_nonblock(sock, TRUE);
 
   /* wait until socket gets connected */
-  result = Curl_socket_ready(CURL_SOCKET_BAD, sock, (int)timeout);
+  result = Curl_socket_ready(conn, CURL_SOCKET_BAD, sock, (int)timeout);
 
   if(-1 == result) {
     failf(conn->data, "SOCKS5: no connection here");
     return CURLE_COULDNT_CONNECT;
   }
+  else if(-2 == result)
+    return CURLE_ABORTED_BY_CALLBACK;
   else if(0 == result) {
     failf(conn->data, "SOCKS5: connection timeout");
     return CURLE_OPERATION_TIMEDOUT;
@@ -441,12 +443,14 @@ CURLcode Curl_SOCKS5(const char *proxy_n
 
   Curl_nonblock(sock, TRUE);
 
-  result = Curl_socket_ready(sock, CURL_SOCKET_BAD, (int)timeout);
+  result = Curl_socket_ready(conn, sock, CURL_SOCKET_BAD, (int)timeout);
 
   if(-1 == result) {
     failf(conn->data, "SOCKS5 nothing to read");
     return CURLE_COULDNT_CONNECT;
   }
+  else if(-2 == result)
+    return CURLE_ABORTED_BY_CALLBACK;
   else if(0 == result) {
     failf(conn->data, "SOCKS5 read timeout");
     return CURLE_OPERATION_TIMEDOUT;
diff -urNp curl-7.18.1-orig/lib/ssluse.c curl-7.18.1/lib/ssluse.c
--- curl-7.18.1-orig/lib/ssluse.c	2008-02-26 12:45:17.000000000 +0100
+++ curl-7.18.1/lib/ssluse.c	2008-04-12 04:13:36.000000000 +0200
@@ -776,7 +776,7 @@ int Curl_ossl_shutdown(struct connectdat
 
   if(connssl->handle) {
     while(!done) {
-      int what = Curl_socket_ready(conn->sock[sockindex],
+      int what = Curl_socket_ready(conn, conn->sock[sockindex],
                              CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
       if(what > 0) {
         /* Something to read, let's do it and hope that it is the close
@@ -817,6 +817,10 @@ int Curl_ossl_shutdown(struct connectdat
         done = 1;
         break;
       }
+      else if(-2 == what) {
+        retval = -1;
+        done = 1;
+      }
       else {
         /* anything that gets here is fatally bad */
         failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
@@ -1787,7 +1791,7 @@ ossl_connect_common(struct connectdata *
         connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
 
       while(1) {
-        int what = Curl_socket_ready(readfd, writefd,
+        int what = Curl_socket_ready(conn, readfd, writefd,
                                      nonblocking?0:(int)timeout_ms);
         if(what > 0)
           /* readable or writable, go loop in the outer loop */
@@ -1803,6 +1807,8 @@ ossl_connect_common(struct connectdata *
             return CURLE_OPERATION_TIMEDOUT;
           }
         }
+        else if(-2 == what)
+          return CURLE_ABORTED_BY_CALLBACK;
         else {
           /* anything that gets here is fatally bad */
           failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
diff -urNp curl-7.18.1-orig/lib/telnet.c curl-7.18.1/lib/telnet.c
--- curl-7.18.1-orig/lib/telnet.c	2007-12-09 00:03:52.000000000 +0100
+++ curl-7.18.1/lib/telnet.c	2008-04-12 04:13:36.000000000 +0200
@@ -1381,7 +1381,9 @@ static CURLcode telnet_do(struct connect
   interval_ms = 1 * 1000;
 
   while(keepon) {
-    switch (Curl_poll(pfd, 2, interval_ms)) {
+    switch (Curl_poll(conn, pfd, 2, interval_ms)) {
+    case -2:                    /* aborted by callback */
+      code = CURLE_ABORTED_BY_CALLBACK;
     case -1:                    /* error, stop reading */
       keepon = FALSE;
       continue;
diff -urNp curl-7.18.1-orig/lib/tftp.c curl-7.18.1/lib/tftp.c
--- curl-7.18.1-orig/lib/tftp.c	2008-02-11 23:03:31.000000000 +0100
+++ curl-7.18.1/lib/tftp.c	2008-04-12 04:13:36.000000000 +0200
@@ -744,10 +744,10 @@ static CURLcode tftp_do(struct connectda
       code=tftp_state_machine(state, event) ) {
 
     /* Wait until ready to read or timeout occurs */
-    rc=Curl_socket_ready(state->sockfd, CURL_SOCKET_BAD,
+    rc=Curl_socket_ready(conn, state->sockfd, CURL_SOCKET_BAD,
                          state->retry_time * 1000);
 
-    if(rc == -1) {
+    if(rc == -1 || rc == -2) {
       /* bail out */
       int error = SOCKERRNO;
       failf(data, "%s", Curl_strerror(conn, error));
diff -urNp curl-7.18.1-orig/lib/transfer.c curl-7.18.1/lib/transfer.c
--- curl-7.18.1-orig/lib/transfer.c	2008-03-22 23:00:21.000000000 +0100
+++ curl-7.18.1/lib/transfer.c	2008-04-12 04:13:36.000000000 +0200
@@ -363,7 +363,7 @@ CURLcode Curl_readwrite(struct connectda
 
    if(!select_res) { /* Call for select()/poll() only, if read/write/error
                          status is not known. */
-       select_res = Curl_socket_ready(fd_read, fd_write, 0);
+       select_res = Curl_socket_ready(conn, fd_read, fd_write, 0);
    }
 
   if(select_res == CURL_CSELECT_ERR) {
@@ -1800,17 +1800,13 @@ Transfer(struct connectdata *conn)
        must make sure that this function doesn't transfer anything while in
        HOLD status. */
 
-    switch (Curl_socket_ready(fd_read, fd_write, 1000)) {
+    switch (Curl_socket_ready(conn, fd_read, fd_write, 1000)) {
     case -1: /* select() error, stop reading */
-#ifdef EINTR
-      /* The EINTR is not serious, and it seems you might get this more
-         ofen when using the lib in a multi-threaded environment! */
-      if(SOCKERRNO == EINTR)
-        ;
-      else
-#endif
-        done = TRUE; /* no more read or write */
+      done = TRUE; /* no more read or write */
       continue;
+    case -2: /* aborted by callback */
+      result = CURLE_ABORTED_BY_CALLBACK;
+      break;
     case 0:  /* timeout */
     default: /* readable descriptors */
 
diff -urNp curl-7.18.1-orig/lib/url.c curl-7.18.1/lib/url.c
--- curl-7.18.1-orig/lib/url.c	2008-03-25 23:30:02.000000000 +0100
+++ curl-7.18.1/lib/url.c	2008-04-12 04:13:36.000000000 +0200
@@ -2216,12 +2216,12 @@ CURLcode Curl_disconnect(struct connectd
  * be dead. Most commonly this happens when the server has closed the
  * connection due to inactivity.
  */
-static bool SocketIsDead(curl_socket_t sock)
+static bool SocketIsDead(struct connectdata *conn, curl_socket_t sock)
 {
   int sval;
   bool ret_val = TRUE;
 
-  sval = Curl_socket_ready(sock, CURL_SOCKET_BAD, 0);
+  sval = Curl_socket_ready(conn, sock, CURL_SOCKET_BAD, 0);
   if(sval == 0)
     /* timeout */
     ret_val = FALSE;
@@ -2490,7 +2490,7 @@ ConnectionExists(struct SessionHandle *d
       if(pipeLen == 0) {
         /* The check for a dead socket makes sense only if there
            are no handles in pipeline */
-        bool dead = SocketIsDead(check->sock[FIRSTSOCKET]);
+        bool dead = SocketIsDead(needle, check->sock[FIRSTSOCKET]);
         if(dead) {
           check->data = data;
           infof(data, "Connection #%d seems to be dead!\n", i);

