upkeep: add a connection upkeep API: curl_easy_conn_upkeep()

Add functionality so that protocols can do custom keepalive on their
connections, when an external API function is called.

Add docs for the new options in 7.62.0

Closes #1641
This commit is contained in:
Max Dymond 2018-04-18 16:40:17 +01:00 committed by Daniel Stenberg
parent 6684653b68
commit 7b655fcbad
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
15 changed files with 280 additions and 2 deletions

View file

@ -233,12 +233,43 @@ static unsigned int http2_conncheck(struct connectdata *check,
unsigned int checks_to_perform)
{
unsigned int ret_val = CONNRESULT_NONE;
struct http_conn *c = &check->proto.httpc;
int rc;
bool send_frames = false;
if(checks_to_perform & CONNCHECK_ISDEAD) {
if(http2_connisdead(check))
ret_val |= CONNRESULT_DEAD;
}
if(checks_to_perform & CONNCHECK_KEEPALIVE) {
struct curltime now = Curl_now();
time_t elapsed = Curl_timediff(now, check->keepalive);
if(elapsed > check->upkeep_interval_ms) {
/* Perform an HTTP/2 PING */
rc = nghttp2_submit_ping(c->h2, 0, ZERO_NULL);
if(!rc) {
/* Successfully added a PING frame to the session. Need to flag this
so the frame is sent. */
send_frames = true;
}
else {
failf(check->data, "nghttp2_submit_ping() failed: %s(%d)",
nghttp2_strerror(rc), rc);
}
check->keepalive = now;
}
}
if(send_frames) {
rc = nghttp2_session_send(c->h2);
if(rc)
failf(check->data, "nghttp2_session_send() failed: %s(%d)",
nghttp2_strerror(rc), rc);
}
return ret_val;
}