diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-05-27 01:01:44 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-05-27 01:01:44 +0200 |
commit | 5507adbe9473f4b41e52d16498f14850773e5e45 (patch) | |
tree | 34f2960edf6b73828537460cc50e6cdb9252a5e3 /src/network/poller.cpp | |
parent | 6b0ffb5fc2eca537e2cfaf24acb8a4d2ca9b99f1 (diff) | |
download | biboumi-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/network/poller.cpp')
-rw-r--r-- | src/network/poller.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/network/poller.cpp b/src/network/poller.cpp index 708fe23..d89e50f 100644 --- a/src/network/poller.cpp +++ b/src/network/poller.cpp @@ -27,15 +27,14 @@ Poller::~Poller() { } -void Poller::add_socket_handler(std::shared_ptr<SocketHandler> socket_handler) +void Poller::add_socket_handler(SocketHandler* socket_handler) { - // Raise an error if that socket is already in the list + // Don't do anything if the socket is already managed const auto it = this->socket_handlers.find(socket_handler->get_socket()); if (it != this->socket_handlers.end()) - throw std::runtime_error("Trying to insert SocketHandler already managed"); + return ; this->socket_handlers.emplace(socket_handler->get_socket(), socket_handler); - socket_handler->set_poller(this); // We always watch all sockets for receive events #if POLLER == POLL @@ -44,7 +43,7 @@ void Poller::add_socket_handler(std::shared_ptr<SocketHandler> socket_handler) this->nfds++; #endif #if POLLER == EPOLL - struct epoll_event event = {EPOLLIN, {socket_handler.get()}}; + struct epoll_event event = {EPOLLIN, {socket_handler}}; const int res = ::epoll_ctl(this->epfd, EPOLL_CTL_ADD, socket_handler->get_socket(), &event); if (res == -1) { |