From 5507adbe9473f4b41e52d16498f14850773e5e45 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Tue, 27 May 2014 01:01:44 +0200 Subject: SocketHandlers own the poller and add themself into it only when the socket is created MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to call socket() with the parameters provided by getaddrinfo, so we can’t addd the fd into the poller immediately. We need to wait the connection attempt, and then the SocketHandler can call add_socket_handler itself, if the connection succeeds, or is in progress. --- src/main.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 6cba134..40825c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -61,11 +61,11 @@ int main(int ac, char** av) return config_help("password"); if (hostname.empty()) return config_help("hostname"); - std::shared_ptr xmpp_component = - std::make_shared(hostname, password); - Poller p; - p.add_socket_handler(xmpp_component); + auto p = std::make_shared(); + auto xmpp_component = std::make_shared(p, + hostname, + password); // Install the signals used to exit the process cleanly, or reload the // config @@ -91,7 +91,7 @@ int main(int ac, char** av) xmpp_component->start(); const std::chrono::milliseconds timeout(-1); - while (p.poll(timeout) != -1) + while (p->poll(timeout) != -1) { // Check for empty irc_clients (not connected, or with no joined // channel) and remove them @@ -123,14 +123,13 @@ int main(int ac, char** av) !xmpp_component->is_connecting()) { xmpp_component->reset(); - p.add_socket_handler(xmpp_component); xmpp_component->start(); } // If the only existing connection is the one to the XMPP component: // close the XMPP stream. if (exiting && xmpp_component->is_connecting()) xmpp_component->close(); - if (exiting && p.size() == 1 && xmpp_component->is_document_open()) + if (exiting && p->size() == 1 && xmpp_component->is_document_open()) xmpp_component->close_document(); } log_info("All connection cleanely closed, have a nice day."); -- cgit v1.2.3