diff --git a/src/h2load.cc b/src/h2load.cc index 24276f6e..dc164b28 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -202,7 +202,9 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) { auto client = static_cast(w->data); client->restart_timeout(); if (client->do_read() != 0) { - client->fail(); + if (client->try_again_or_fail() == 0) { + return; + } delete client; return; } @@ -453,7 +455,7 @@ void Client::restart_timeout() { } } -void Client::fail() { +int Client::try_again_or_fail() { disconnect(); if (new_connection_requested) { @@ -471,13 +473,21 @@ void Client::fail() { // Keep using current address if (connect() == 0) { - return; + return 0; } std::cerr << "client could not connect to host" << std::endl; } } process_abandoned_streams(); + + return -1; +} + +void Client::fail() { + disconnect(); + + process_abandoned_streams(); } void Client::disconnect() { diff --git a/src/h2load.h b/src/h2load.h index c053b9c8..de11b4b4 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -307,6 +307,12 @@ struct Client { int connect(); void disconnect(); void fail(); + // Call this function when do_read() returns -1. This function + // tries to connect to the remote host again if it is requested. If + // so, this function returns 0, and this object should be retained. + // Otherwise, this function returns -1, and this object should be + // deleted. + int try_again_or_fail(); void timeout(); void restart_timeout(); int submit_request();