client: defer notification of connect() failure
... to bevEvent() callback to handle early failure the same as later disconnect.
This commit is contained in:
committed by
mdavidsaver
parent
614e0b7e09
commit
c3e91f60be
+15
-2
@@ -71,8 +71,16 @@ void Connection::startConnecting()
|
||||
timeval tmo(totv(context->effective.tcpTimeout));
|
||||
bufferevent_set_timeouts(bev.get(), &tmo, &tmo);
|
||||
|
||||
if(bufferevent_socket_connect(bev.get(), const_cast<sockaddr*>(&peerAddr->sa), peerAddr.size()))
|
||||
throw std::runtime_error("Unable to begin connecting");
|
||||
if(bufferevent_socket_connect(bev.get(), const_cast<sockaddr*>(&peerAddr->sa), peerAddr.size())) {
|
||||
// non-blocking connect() failed immediately.
|
||||
// try to defer notification.
|
||||
state = Disconnected;
|
||||
constexpr timeval immediate{0, 0};
|
||||
if(event_add(echoTimer.get(), &immediate))
|
||||
throw std::runtime_error(SB()<<"Unable to begin connecting or schedule deferred notification "<<peerName);
|
||||
log_warn_printf(io, "Unable to connect() to %s\n", peerName.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
connect(std::move(bev));
|
||||
|
||||
@@ -480,6 +488,11 @@ void Connection::tickEcho()
|
||||
|
||||
startConnecting();
|
||||
|
||||
}else if(state==Disconnected) {
|
||||
// deferred notification of early connect() failure.
|
||||
// TODO: avoid a misleading "closed by peer" error
|
||||
bevEvent(BEV_EVENT_EOF);
|
||||
|
||||
} else {
|
||||
log_debug_printf(io, "Server %s ping\n", peerName.c_str());
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ struct Connection final : public ConnBase, public std::enable_shared_from_this<C
|
||||
|
||||
// While HoldOff, the time until re-connection
|
||||
// While Connected, periodic Echo
|
||||
// After early connect() failure, deferred notification
|
||||
const evevent echoTimer;
|
||||
|
||||
bool ready = false;
|
||||
|
||||
Reference in New Issue
Block a user