Skip to content

Commit

Permalink
Add a setopt for happy eyeballs timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andersbakken committed Sep 28, 2017
1 parent 3e50c6a commit ed1fb2d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/curl/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,9 @@ typedef enum {
/* Post MIME data. */
CINIT(MIMEPOST, OBJECTPOINT, 269),

/* Head start in milliseconds to give ipv6 for happy eyeballs. */
CINIT(HAPPY_EYEBALLS_TIMEOUT, LONG, 271),

CURLOPT_LASTENTRY /* the last unused */
} CURLoption;

Expand Down
14 changes: 11 additions & 3 deletions lib/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
struct curltime now;
int rc;
int i;
long happyTimeout = data->set.happy_eyeballs_timeout;
if(!happyTimeout)
happyTimeout = HAPPY_EYEBALLS_TIMEOUT;

DEBUGASSERT(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);

Expand Down Expand Up @@ -773,7 +776,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,

/* should we try another protocol family? */
if(i == 0 && conn->tempaddr[1] == NULL &&
curlx_tvdiff(now, conn->connecttime) >= HAPPY_EYEBALLS_TIMEOUT) {
curlx_tvdiff(now, conn->connecttime) >= happyTimeout) {
trynextip(conn, sockindex, 1);
}
}
Expand Down Expand Up @@ -1147,8 +1150,13 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
struct Curl_easy *data = conn->data;
struct curltime before = Curl_tvnow();
CURLcode result = CURLE_COULDNT_CONNECT;
long happyTimeout = data->set.happy_eyeballs_timeout;
time_t timeout_ms;

time_t timeout_ms = Curl_timeleft(data, &before, TRUE);
if(!happyTimeout)
happyTimeout = HAPPY_EYEBALLS_TIMEOUT;

timeout_ms = Curl_timeleft(data, &before, TRUE);

if(timeout_ms < 0) {
/* a precaution, no need to continue if time already is up */
Expand Down Expand Up @@ -1181,7 +1189,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
}

data->info.numconnects++; /* to track the number of connections made */
Curl_expire(conn->data, HAPPY_EYEBALLS_TIMEOUT, EXPIRE_HAPPY_EYEBALLS);
Curl_expire(conn->data, happyTimeout, EXPIRE_HAPPY_EYEBALLS);

return CURLE_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -2964,6 +2964,9 @@ CURLcode Curl_setopt(struct Curl_easy *data, CURLoption option,
case CURLOPT_SSH_COMPRESSION:
data->set.ssh_compression = (0 != va_arg(param, long))?TRUE:FALSE;
break;
case CURLOPT_HAPPY_EYEBALLS_TIMEOUT:
data->set.happy_eyeballs_timeout = va_arg(param, long);
break;
default:
/* unknown tag and its companion, just ignore: */
result = CURLE_UNKNOWN_OPTION;
Expand Down
1 change: 1 addition & 0 deletions lib/urldata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ struct UserDefined {
long timeout; /* in milliseconds, 0 means no timeout */
long connecttimeout; /* in milliseconds, 0 means no timeout */
long accepttimeout; /* in milliseconds, 0 means no timeout */
long happy_eyeballs_timeout; /* in milliseconds, 0 means default */
long server_response_timeout; /* in milliseconds, 0 means no timeout */
long tftp_blksize; /* in bytes, 0 means use default */
bool tftp_no_options; /* do not send TFTP options requests */
Expand Down

0 comments on commit ed1fb2d

Please sign in to comment.