summaryrefslogtreecommitdiff
path: root/src/bridge
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/bridge
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/bridge')
-rw-r--r--src/bridge/bridge.cpp5
-rw-r--r--src/bridge/bridge.hpp5
2 files changed, 4 insertions, 6 deletions
diff --git a/src/bridge/bridge.cpp b/src/bridge/bridge.cpp
index d803e5e..78cd2d2 100644
--- a/src/bridge/bridge.cpp
+++ b/src/bridge/bridge.cpp
@@ -14,7 +14,7 @@ using namespace std::string_literals;
static const char* action_prefix = "\01ACTION ";
-Bridge::Bridge(const std::string& user_jid, XmppComponent* xmpp, Poller* poller):
+Bridge::Bridge(const std::string& user_jid, XmppComponent* xmpp, std::shared_ptr<Poller> poller):
user_jid(user_jid),
xmpp(xmpp),
poller(poller)
@@ -81,9 +81,8 @@ IrcClient* Bridge::get_irc_client(const std::string& hostname, const std::string
}
catch (const std::out_of_range& exception)
{
- this->irc_clients.emplace(hostname, std::make_shared<IrcClient>(hostname, username, this));
+ this->irc_clients.emplace(hostname, std::make_shared<IrcClient>(this->poller, hostname, username, this));
std::shared_ptr<IrcClient> irc = this->irc_clients.at(hostname);
- this->poller->add_socket_handler(irc);
return irc.get();
}
}
diff --git a/src/bridge/bridge.hpp b/src/bridge/bridge.hpp
index f78bade..37f5b05 100644
--- a/src/bridge/bridge.hpp
+++ b/src/bridge/bridge.hpp
@@ -22,7 +22,7 @@ class Poller;
class Bridge
{
public:
- explicit Bridge(const std::string& user_jid, XmppComponent* xmpp, Poller* poller);
+ explicit Bridge(const std::string& user_jid, XmppComponent* xmpp, std::shared_ptr<Poller> poller);
~Bridge();
/**
* QUIT all connected IRC servers.
@@ -146,9 +146,8 @@ private:
/**
* Poller, to give it the IrcClients that we spawn, to make it manage
* their sockets.
- * We don't own it.
*/
- Poller* poller;
+ std::shared_ptr<Poller> poller;
Bridge(const Bridge&) = delete;
Bridge(Bridge&& other) = delete;