diff --git a/src/h2load.cc b/src/h2load.cc index 7c6dc2e1..6317196b 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -107,7 +107,17 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) { namespace { void writecb(struct ev_loop *loop, ev_io *w, int revents) { auto client = static_cast(w->data); - if (client->do_write() != 0) { + auto rv = client->do_write(); + if (rv == Client::ERR_CONNECT_FAIL) { + client->disconnect(); + rv = client->connect(); + if (rv != 0) { + client->fail(); + return; + } + return; + } + if (rv != 0) { client->fail(); } } @@ -533,6 +543,9 @@ int Client::write_clear() { } int Client::connected() { + if (!util::check_socket_connected(fd)) { + return ERR_CONNECT_FAIL; + } ev_io_start(worker->loop, &rev); ev_io_stop(worker->loop, &wev); diff --git a/src/h2load.h b/src/h2load.h index ac02cb98..6ff53525 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -149,6 +149,8 @@ struct Client { int fd; RingBuf<65536> wb; + enum { ERR_CONNECT_FAIL = -100 }; + Client(Worker *worker, size_t req_todo); ~Client(); int connect();