summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2016-02-24 09:29:28 +0100
committerFlorent Le Coz <louiz@louiz.org>2016-02-24 09:31:30 +0100
commitb47179f1256f2a3fe6ce0d8f30eceb0f91b33b2e (patch)
tree5a47aa434a61a9f0e3dc8d49ff5ea6516913052f
parentb29d94444d176604f0847985f3ecf57091d4a47b (diff)
downloadbiboumi-b47179f1256f2a3fe6ce0d8f30eceb0f91b33b2e.tar.gz
biboumi-b47179f1256f2a3fe6ce0d8f30eceb0f91b33b2e.tar.bz2
biboumi-b47179f1256f2a3fe6ce0d8f30eceb0f91b33b2e.tar.xz
biboumi-b47179f1256f2a3fe6ce0d8f30eceb0f91b33b2e.zip
Fix the ordering of poll callbacks, with ppoll too
-rw-r--r--louloulibs/network/poller.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/louloulibs/network/poller.cpp b/louloulibs/network/poller.cpp
index 0559644..26e5a8f 100644
--- a/louloulibs/network/poller.cpp
+++ b/louloulibs/network/poller.cpp
@@ -171,21 +171,22 @@ int Poller::poll(const std::chrono::milliseconds& timeout)
assert(static_cast<unsigned int>(nb_events) <= this->nfds);
for (size_t i = 0; i <= this->nfds && nb_events != 0; ++i)
{
+ auto socket_handler = this->socket_handlers.at(this->fds[i].fd);
if (this->fds[i].revents == 0)
continue;
- else if (this->fds[i].revents & POLLIN)
+ else if (this->fds[i].revents & POLLIN && socket_handler->is_connected())
{
- auto socket_handler = this->socket_handlers.at(this->fds[i].fd);
socket_handler->on_recv();
nb_events--;
}
- else if (this->fds[i].revents & POLLOUT)
+ else if (this->fds[i].revents & POLLOUT && socket_handler->is_connected())
{
- auto socket_handler = this->socket_handlers.at(this->fds[i].fd);
- if (socket_handler->is_connected())
socket_handler->on_send();
- else
- socket_handler->connect();
+ nb_events--;
+ }
+ else if (this->fds[i].revents & POLLOUT)
+ {
+ socket_handler->connect();
nb_events--;
}
}