request timeout support in HttpRequest

This commit is contained in:
GallaFrancesco 2021-03-31 10:22:01 +00:00
parent f8af877e4f
commit 1078bcacce
1 changed files with 8 additions and 5 deletions

13
http2.d
View File

@ -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); populateFromInfo(where, method);
this.timeout = timeout;
this.cache = cache; this.cache = cache;
} }
Duration timeout;
private Uri where; private Uri where;
private ICache cache; private ICache cache;
@ -880,7 +883,7 @@ class HttpRequest {
} }
if(advance) if(advance)
HttpRequest.advanceConnections(); HttpRequest.advanceConnections(this.timeout);
} }
@ -891,7 +894,7 @@ class HttpRequest {
send(); send();
continue; continue;
} }
if(auto err = HttpRequest.advanceConnections()) { if(auto err = HttpRequest.advanceConnections(this.timeout)) {
switch(err) { switch(err) {
case 1: throw new Exception("HttpRequest.advanceConnections returned 1: all connections timed out"); 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"); case 2: throw new Exception("HttpRequest.advanceConnections returned 2: nothing to do");
@ -1034,7 +1037,7 @@ class HttpRequest {
SocketSet writeSet; SocketSet writeSet;
int advanceConnections() { int advanceConnections(Duration timeout=10.seconds) {
if(readSet is null) if(readSet is null)
readSet = new SocketSet(); readSet = new SocketSet();
if(writeSet is null) 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 */ if(selectGot == 0) { /* timeout */
// FIXME: individual requests should have different time outs... // FIXME: individual requests should have different time outs...
foreach(sock, request; activeRequestOnSocket) { foreach(sock, request; activeRequestOnSocket) {