--- url.c.org	Wed Jan  2 18:51:43 2002
+++ url.c	Wed Jan  2 18:57:51 2002
@@ -2020,48 +2020,8 @@
     }
   }
   Curl_pgrsTime(data, TIMER_NAMELOOKUP);
-#ifdef HAVE_ALARM
-  if(data->set.timeout || data->set.connecttimeout) {
-#ifdef HAVE_SIGACTION
-    if(keep_copysig) {
-      /* we got a struct as it looked before, now put that one back nice
-         and clean */
-      sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */
-    }
-#else
-#ifdef HAVE_SIGNAL
-    /* restore the previous SIGALRM handler */
-    signal(SIGALRM, keep_sigact);
-#endif
-#endif
-    /* switch back the alarm() to either zero or to what it was before minus
-       the time we spent until now! */
-    if(prev_alarm) {
-      /* there was an alarm() set before us, now put it back */
-      long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);
-      long alarm_set;
-
-      /* the alarm period is counted in even number of seconds */
-      alarm_set = prev_alarm - elapsed_ms/1000;
-
-      if(alarm_set<=0) {
-        /* if it turned negative, we should fire off a SIGALRM here, but we
-           won't, and zero would be to switch it off so we never set it to
-           less than 1! */
-        alarm(1);
-        result = CURLE_OPERATION_TIMEOUTED;
-        failf(data, "Previous alarm fired off!");
-      }
-      else
-        alarm(alarm_set);
-    }
-    else
-      alarm(0); /* just shut it off */
-  }
-#endif
-  if(result)
-    return result;
 
+  if (result == CURLE_OK) {
   /*************************************************************
    * Proxy authentication
    *************************************************************/
@@ -2095,10 +2055,7 @@
   if(-1 == conn->firstsocket) {
     /* Connect only if not already connected! */
     result = ConnectPlease(conn);
-    if(CURLE_OK != result)
-      return result;
-
-    if(conn->curl_connect) {
+      if (result == CURLE_OK && conn->curl_connect) {
       /* is there a connect() procedure? */
 
       /* set start time here for timeout purposes in the
@@ -2108,10 +2065,52 @@
 
       /* Call the protocol-specific connect function */
       result = conn->curl_connect(conn);
-      if(result != CURLE_OK)
-        return result; /* pass back errors */
     }
   }
+  }
+
+  /* Restore the alarm stuff */
+#ifdef HAVE_ALARM
+  if(data->set.timeout || data->set.connecttimeout) {
+#ifdef HAVE_SIGACTION
+    if(keep_copysig) {
+      /* we got a struct as it looked before, now put that one back nice
+         and clean */
+      sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */
+    }
+#else
+#ifdef HAVE_SIGNAL
+    /* restore the previous SIGALRM handler */
+    signal(SIGALRM, keep_sigact);
+#endif
+#endif
+    /* switch back the alarm() to either zero or to what it was before minus
+       the time we spent until now! */
+    if(prev_alarm) {
+      /* there was an alarm() set before us, now put it back */
+      long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);
+      long alarm_set;
+
+      /* the alarm period is counted in even number of seconds */
+      alarm_set = prev_alarm - elapsed_ms/1000;
+
+      if(alarm_set<=0) {
+        /* if it turned negative, we should fire off a SIGALRM here, but we
+           won't, and zero would be to switch it off so we never set it to
+           less than 1! */
+        alarm(1);
+        result = CURLE_OPERATION_TIMEOUTED;
+        failf(data, "Previous alarm fired off!");
+      }
+      else
+        alarm(alarm_set);
+    }
+    else
+      alarm(0); /* just shut it off */
+  }
+#endif
+  if (result != CURLE_OK)
+    return result;
 
   Curl_pgrsTime(data, TIMER_CONNECT); /* we're connected */
 


