h2load: Fix bug that it did not try to connect to server again

This commit is contained in:
Tatsuhiro Tsujikawa 2016-03-02 22:24:14 +09:00
parent ce61f62644
commit 5da38b22c0
2 changed files with 19 additions and 3 deletions

View File

@ -202,7 +202,9 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) {
auto client = static_cast<Client *>(w->data); auto client = static_cast<Client *>(w->data);
client->restart_timeout(); client->restart_timeout();
if (client->do_read() != 0) { if (client->do_read() != 0) {
client->fail(); if (client->try_again_or_fail() == 0) {
return;
}
delete client; delete client;
return; return;
} }
@ -453,7 +455,7 @@ void Client::restart_timeout() {
} }
} }
void Client::fail() { int Client::try_again_or_fail() {
disconnect(); disconnect();
if (new_connection_requested) { if (new_connection_requested) {
@ -471,13 +473,21 @@ void Client::fail() {
// Keep using current address // Keep using current address
if (connect() == 0) { if (connect() == 0) {
return; return 0;
} }
std::cerr << "client could not connect to host" << std::endl; std::cerr << "client could not connect to host" << std::endl;
} }
} }
process_abandoned_streams(); process_abandoned_streams();
return -1;
}
void Client::fail() {
disconnect();
process_abandoned_streams();
} }
void Client::disconnect() { void Client::disconnect() {

View File

@ -307,6 +307,12 @@ struct Client {
int connect(); int connect();
void disconnect(); void disconnect();
void fail(); 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 timeout();
void restart_timeout(); void restart_timeout();
int submit_request(); int submit_request();