mirror of
https://github.com/moparisthebest/curl
synced 2024-12-21 23:58:49 -05:00
added connect timeout support
This commit is contained in:
parent
36c88343d3
commit
d6c456db85
88
lib/url.c
88
lib/url.c
@ -122,6 +122,19 @@ static unsigned int ConnectionStore(struct UrlData *data,
|
|||||||
struct connectdata *conn);
|
struct connectdata *conn);
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(WIN32)||defined(__CYGWIN32__)
|
||||||
|
#ifndef RETSIGTYPE
|
||||||
|
#define RETSIGTYPE void
|
||||||
|
#endif
|
||||||
|
static
|
||||||
|
RETSIGTYPE alarmfunc(int signal)
|
||||||
|
{
|
||||||
|
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
|
||||||
|
(void)signal;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
CURLcode Curl_close(CURL *curl)
|
CURLcode Curl_close(CURL *curl)
|
||||||
{
|
{
|
||||||
struct UrlData *data=(struct UrlData *)curl;
|
struct UrlData *data=(struct UrlData *)curl;
|
||||||
@ -186,6 +199,9 @@ CURLcode Curl_open(CURL **curl, char *url)
|
|||||||
{
|
{
|
||||||
/* We don't yet support specifying the URL at this point */
|
/* We don't yet support specifying the URL at this point */
|
||||||
struct UrlData *data;
|
struct UrlData *data;
|
||||||
|
#ifdef HAVE_SIGACTION
|
||||||
|
struct sigaction sigact;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Very simple start-up: alloc the struct, init it with zeroes and return */
|
/* Very simple start-up: alloc the struct, init it with zeroes and return */
|
||||||
data = (struct UrlData *)malloc(sizeof(struct UrlData));
|
data = (struct UrlData *)malloc(sizeof(struct UrlData));
|
||||||
@ -234,6 +250,26 @@ CURLcode Curl_open(CURL **curl, char *url)
|
|||||||
memset(data->connects, 0, sizeof(struct connectdata *)*data->numconnects);
|
memset(data->connects, 0, sizeof(struct connectdata *)*data->numconnects);
|
||||||
|
|
||||||
*curl = data;
|
*curl = data;
|
||||||
|
|
||||||
|
/*************************************************************
|
||||||
|
* Set signal handler
|
||||||
|
*************************************************************/
|
||||||
|
#ifdef HAVE_SIGACTION
|
||||||
|
sigaction(SIGALRM, NULL, &sigact);
|
||||||
|
sigact.sa_handler = alarmfunc;
|
||||||
|
#ifdef SA_RESTART
|
||||||
|
/* HPUX doesn't have SA_RESTART but defaults to that behaviour! */
|
||||||
|
sigact.sa_flags &= ~SA_RESTART;
|
||||||
|
#endif
|
||||||
|
sigaction(SIGALRM, &sigact, NULL);
|
||||||
|
#else
|
||||||
|
/* no sigaction(), revert to the much lamer signal() */
|
||||||
|
#ifdef HAVE_SIGNAL
|
||||||
|
signal(SIGALRM, alarmfunc);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,6 +631,12 @@ CURLcode Curl_setopt(CURL *curl, CURLoption option, ...)
|
|||||||
*/
|
*/
|
||||||
data->timeout = va_arg(param, long);
|
data->timeout = va_arg(param, long);
|
||||||
break;
|
break;
|
||||||
|
case CURLOPT_CONNECTTIMEOUT:
|
||||||
|
/*
|
||||||
|
* The maximum time you allow curl to use to connect.
|
||||||
|
*/
|
||||||
|
data->connecttimeout = va_arg(param, long);
|
||||||
|
break;
|
||||||
case CURLOPT_MAXREDIRS:
|
case CURLOPT_MAXREDIRS:
|
||||||
/*
|
/*
|
||||||
* The maximum amount of hops you allow curl to follow Location:
|
* The maximum amount of hops you allow curl to follow Location:
|
||||||
@ -748,19 +790,6 @@ CURLcode Curl_setopt(CURL *curl, CURLoption option, ...)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(WIN32)||defined(__CYGWIN32__)
|
|
||||||
#ifndef RETSIGTYPE
|
|
||||||
#define RETSIGTYPE void
|
|
||||||
#endif
|
|
||||||
static
|
|
||||||
RETSIGTYPE alarmfunc(int signal)
|
|
||||||
{
|
|
||||||
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
|
|
||||||
(void)signal;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CURLcode Curl_disconnect(struct connectdata *conn)
|
CURLcode Curl_disconnect(struct connectdata *conn)
|
||||||
{
|
{
|
||||||
if(!conn)
|
if(!conn)
|
||||||
@ -1246,9 +1275,6 @@ static CURLcode Connect(struct UrlData *data,
|
|||||||
struct connectdata *conn;
|
struct connectdata *conn;
|
||||||
struct connectdata *conn_temp;
|
struct connectdata *conn_temp;
|
||||||
char endbracket;
|
char endbracket;
|
||||||
#ifdef HAVE_SIGACTION
|
|
||||||
struct sigaction sigact;
|
|
||||||
#endif
|
|
||||||
int urllen;
|
int urllen;
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
@ -1388,25 +1414,6 @@ static CURLcode Connect(struct UrlData *data,
|
|||||||
|
|
||||||
buf = data->buffer; /* this is our buffer */
|
buf = data->buffer; /* this is our buffer */
|
||||||
|
|
||||||
/*************************************************************
|
|
||||||
* Set signal handler
|
|
||||||
*************************************************************/
|
|
||||||
#ifdef HAVE_SIGACTION
|
|
||||||
sigaction(SIGALRM, NULL, &sigact);
|
|
||||||
sigact.sa_handler = alarmfunc;
|
|
||||||
#ifdef SA_RESTART
|
|
||||||
/* HPUX doesn't have SA_RESTART but defaults to that behaviour! */
|
|
||||||
sigact.sa_flags &= ~SA_RESTART;
|
|
||||||
#endif
|
|
||||||
sigaction(SIGALRM, &sigact, NULL);
|
|
||||||
#else
|
|
||||||
/* no sigaction(), revert to the much lamer signal() */
|
|
||||||
#ifdef HAVE_SIGNAL
|
|
||||||
signal(SIGALRM, alarmfunc);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Take care of user and password authentication stuff
|
* Take care of user and password authentication stuff
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
@ -1603,11 +1610,16 @@ static CURLcode Connect(struct UrlData *data,
|
|||||||
/*************************************************************
|
/*************************************************************
|
||||||
* Set timeout if that is being used
|
* Set timeout if that is being used
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
if(data->timeout) {
|
if(data->timeout || data->connecttimeout) {
|
||||||
/* We set the timeout on the connection/resolving phase first, separately
|
/* We set the timeout on the connection/resolving phase first, separately
|
||||||
* from the download/upload part to allow a maximum time on everything */
|
* from the download/upload part to allow a maximum time on everything */
|
||||||
myalarm(data->timeout); /* this sends a signal when the timeout fires
|
|
||||||
off, and that will abort system calls */
|
/* myalarm() makes a signal get sent when the timeout fires off, and that
|
||||||
|
will abort system calls */
|
||||||
|
if(data->connecttimeout)
|
||||||
|
myalarm(data->connecttimeout);
|
||||||
|
else
|
||||||
|
myalarm(data->timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
|
@ -496,8 +496,9 @@ struct UrlData {
|
|||||||
curl_passwd_callback fpasswd;
|
curl_passwd_callback fpasswd;
|
||||||
void *passwd_client; /* pointer to pass to the passwd callback */
|
void *passwd_client; /* pointer to pass to the passwd callback */
|
||||||
|
|
||||||
long timeout; /* in seconds, 0 means no timeout */
|
long timeout; /* in seconds, 0 means no timeout */
|
||||||
long infilesize; /* size of file to upload, -1 means unknown */
|
long connecttimeout; /* in seconds, 0 means no timeout */
|
||||||
|
long infilesize; /* size of file to upload, -1 means unknown */
|
||||||
|
|
||||||
char buffer[BUFSIZE+1]; /* buffer with size BUFSIZE */
|
char buffer[BUFSIZE+1]; /* buffer with size BUFSIZE */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user