From 1078bcacce57dc22d23df00243c2fc6b79cd469c Mon Sep 17 00:00:00 2001 From: GallaFrancesco Date: Wed, 31 Mar 2021 10:22:01 +0000 Subject: [PATCH] request timeout support in HttpRequest --- http2.d | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/http2.d b/http2.d index 373579e..9f26aa9 100644 --- a/http2.d +++ b/http2.d @@ -719,11 +719,14 @@ class HttpRequest { } /// - this(Uri where, HttpVerb method, ICache cache = null) { + this(Uri where, HttpVerb method, ICache cache = null, Duration timeout = 10.seconds) { populateFromInfo(where, method); + this.timeout = timeout; this.cache = cache; } + Duration timeout; + private Uri where; private ICache cache; @@ -880,7 +883,7 @@ class HttpRequest { } if(advance) - HttpRequest.advanceConnections(); + HttpRequest.advanceConnections(this.timeout); } @@ -891,7 +894,7 @@ class HttpRequest { send(); continue; } - if(auto err = HttpRequest.advanceConnections()) { + if(auto err = HttpRequest.advanceConnections(this.timeout)) { switch(err) { case 1: throw new Exception("HttpRequest.advanceConnections returned 1: all connections timed out"); case 2: throw new Exception("HttpRequest.advanceConnections returned 2: nothing to do"); @@ -1034,7 +1037,7 @@ class HttpRequest { SocketSet writeSet; - int advanceConnections() { + int advanceConnections(Duration timeout=10.seconds) { if(readSet is null) readSet = new SocketSet(); if(writeSet is null) @@ -1123,7 +1126,7 @@ class HttpRequest { } } - auto selectGot = Socket.select(readSet, writeSet, null, 10.seconds /* timeout */); // FIXME: adjust timeout based on the individual requests + auto selectGot = Socket.select(readSet, writeSet, null, timeout /* timeout */); // FIXME: adjust timeout based on the individual requests if(selectGot == 0) { /* timeout */ // FIXME: individual requests should have different time outs... foreach(sock, request; activeRequestOnSocket) {