summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-05-27 01:01:44 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-05-27 01:01:44 +0200
commit5507adbe9473f4b41e52d16498f14850773e5e45 (patch)
tree34f2960edf6b73828537460cc50e6cdb9252a5e3 /src/main.cpp
parent6b0ffb5fc2eca537e2cfaf24acb8a4d2ca9b99f1 (diff)
downloadbiboumi-5507adbe9473f4b41e52d16498f14850773e5e45.tar.gz
biboumi-5507adbe9473f4b41e52d16498f14850773e5e45.tar.bz2
biboumi-5507adbe9473f4b41e52d16498f14850773e5e45.tar.xz
biboumi-5507adbe9473f4b41e52d16498f14850773e5e45.zip
SocketHandlers own the poller and add themself into it only when the socket is created
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.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp13
1 files changed, 6 insertions, 7 deletions
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<XmppComponent> xmpp_component =
- std::make_shared<XmppComponent>(hostname, password);
- Poller p;
- p.add_socket_handler(xmpp_component);
+ auto p = std::make_shared<Poller>();
+ auto xmpp_component = std::make_shared<XmppComponent>(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.");