diff --git a/src/clientconn.cpp b/src/clientconn.cpp index 30af209..b1130b3 100644 --- a/src/clientconn.cpp +++ b/src/clientconn.cpp @@ -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(&peerAddr->sa), peerAddr.size())) - throw std::runtime_error("Unable to begin connecting"); + if(bufferevent_socket_connect(bev.get(), const_cast(&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 "<