summaryrefslogtreecommitdiff
path: root/lib/http2.c
diff options
context:
space:
mode:
authorMax Dymond <max.dymond@metaswitch.com>2018-04-18 16:40:17 +0100
committerDaniel Stenberg <daniel@haxx.se>2018-09-07 09:45:29 +0200
commit7b655fcbadffc3a0297466f1527e05d4a8efe6b2 (patch)
tree16c4b8253794cd6302822d2aef7baf86e3db3a81 /lib/http2.c
parent6684653b682bae0be75ea62bb473b126923952f1 (diff)
downloadcurl-7b655fcbadffc3a0297466f1527e05d4a8efe6b2.tar.gz
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
Diffstat (limited to 'lib/http2.c')
-rw-r--r--lib/http2.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/http2.c b/lib/http2.c
index d76919300..c74974ef4 100644
--- a/lib/http2.c
+++ b/lib/http2.c
@@ -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;
}