From e253d8f6db9a021e268205cede2b47072b5a4ba6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 5 Jan 2015 01:56:02 +0900 Subject: [PATCH] h2load: Retry next address when connection cannot be established --- src/h2load.cc | 15 ++++++++++++++- src/h2load.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) 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();