curl-users
again: connect() timeouts
Date: Thu, 26 Oct 2000 21:01:15 +0200
Hi,
i further investigated the problem with hanging connect() calls and the alarm()
timer. When installing a signal handler with the signal() function, which is
just a wrapper around sigaction(), signals are handled in such a matter that
syscalls are restarted after the signal handler has finished. So we stay in the
connect(), that hangs for minutes if a server is unreachable.
But when we use sigaction() directly, we can specify via a flag that syscalls
should no be restarted, and then the connect() returns with ernno set to EINTR
after the alarm signal. So what about the following patch?
diff -r -c curl-7.3/lib/url.c curl-7.3.1/lib/url.c
*** curl-7.3/lib/url.c Wed Oct 4 14:09:46 2000
--- curl-7.3.1/lib/url.c Thu Oct 26 19:56:21 2000
***************
*** 672,677 ****
--- 672,678 ----
char resumerange[12]="";
struct UrlData *data = curl;
struct connectdata *conn;
+ struct sigaction sigact;
if(!data || (data->handle != STRUCT_OPEN))
return CURLE_BAD_FUNCTION_ARGUMENT; /* TBD: make error codes */
***************
*** 694,702 ****
buf = data->buffer; /* this is our buffer */
! #if 0
! signal(SIGALRM, alarmfunc);
! #endif
/* Parse <url> */
/* We need to parse the url, even when using the proxy, because
--- 695,704 ----
buf = data->buffer; /* this is our buffer */
! sigaction(SIGALRM, NULL, &sigact);
! sigact.sa_handler = alarmfunc;
! sigact.sa_flags &= ~SA_RESTART;
! sigaction(SIGALRM, &sigact, NULL);
/* Parse <url> */
/* We need to parse the url, even when using the proxy, because
***************
*** 1366,1376 ****
failf(data, "Attempt to connect to broadcast address without socket broadcast flag or local firewall rule violated: %d",errno);
break;
#endif
- #ifdef EINTR
case EINTR:
failf(data, "Connection timeouted");
break;
- #endif
#if 0
case EAFNOSUPPORT:
failf(data, "Incorrect address family: %d",errno);
--- 1368,1376 ----
Received on 2000-10-26