h2load: Retry next address when connection cannot be established

This commit is contained in:
Tatsuhiro Tsujikawa 2015-01-05 01:56:02 +09:00
parent 8fb544523c
commit e253d8f6db
2 changed files with 16 additions and 1 deletions

View File

@ -107,7 +107,17 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) {
namespace { namespace {
void writecb(struct ev_loop *loop, ev_io *w, int revents) { void writecb(struct ev_loop *loop, ev_io *w, int revents) {
auto client = static_cast<Client *>(w->data); auto client = static_cast<Client *>(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(); client->fail();
} }
} }
@ -533,6 +543,9 @@ int Client::write_clear() {
} }
int Client::connected() { int Client::connected() {
if (!util::check_socket_connected(fd)) {
return ERR_CONNECT_FAIL;
}
ev_io_start(worker->loop, &rev); ev_io_start(worker->loop, &rev);
ev_io_stop(worker->loop, &wev); ev_io_stop(worker->loop, &wev);

View File

@ -149,6 +149,8 @@ struct Client {
int fd; int fd;
RingBuf<65536> wb; RingBuf<65536> wb;
enum { ERR_CONNECT_FAIL = -100 };
Client(Worker *worker, size_t req_todo); Client(Worker *worker, size_t req_todo);
~Client(); ~Client();
int connect(); int connect();