summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2013-11-03 17:54:07 +0100
committerFlorent Le Coz <louiz@louiz.org>2013-11-03 17:55:23 +0100
commitd834d6ed0647ba7e51e81f600fe259156e2b8070 (patch)
tree4b7b63648e788fc3e1c4f68457c3f3a8baa3cd6d /src
parentf2f94618fcf87b4fc1ad86902c63a7a48be745b8 (diff)
downloadbiboumi-d834d6ed0647ba7e51e81f600fe259156e2b8070.tar.gz
biboumi-d834d6ed0647ba7e51e81f600fe259156e2b8070.tar.bz2
biboumi-d834d6ed0647ba7e51e81f600fe259156e2b8070.tar.xz
biboumi-d834d6ed0647ba7e51e81f600fe259156e2b8070.zip
Exit the poller when it handles no connection at all
Diffstat (limited to 'src')
-rw-r--r--src/irc/irc_client.cpp1
-rw-r--r--src/network/poller.cpp5
-rw-r--r--src/network/poller.hpp3
-rw-r--r--src/network/socket_handler.cpp5
4 files changed, 10 insertions, 4 deletions
diff --git a/src/irc/irc_client.cpp b/src/irc/irc_client.cpp
index 83d1b0d..80f36ee 100644
--- a/src/irc/irc_client.cpp
+++ b/src/irc/irc_client.cpp
@@ -21,7 +21,6 @@ void IrcClient::on_connected()
void IrcClient::on_connection_close()
{
std::cout << "Connection closed by remote server." << std::endl;
- this->close();
}
void IrcClient::parse_in_buffer()
diff --git a/src/network/poller.cpp b/src/network/poller.cpp
index 7ab8bc3..6e86891 100644
--- a/src/network/poller.cpp
+++ b/src/network/poller.cpp
@@ -89,9 +89,11 @@ void Poller::stop_watching_send_events(const SocketHandler* const socket_handler
throw std::runtime_error("Cannot watch a non-registered socket for send events");
}
-void Poller::poll()
+bool Poller::poll()
{
#if POLLER == POLL
+ if (this->nfds == 0)
+ return false;
int res = ::poll(this->fds, this->nfds, -1);
if (res < 0)
{
@@ -119,4 +121,5 @@ void Poller::poll()
}
}
#endif
+ return true;
}
diff --git a/src/network/poller.hpp b/src/network/poller.hpp
index 64e78e4..319236b 100644
--- a/src/network/poller.hpp
+++ b/src/network/poller.hpp
@@ -57,8 +57,9 @@ public:
/**
* Wait for all watched events, and call the SocketHandlers' callbacks
* when one is ready.
+ * Returns false if there are 0 SocketHandler in the list.
*/
- void poll();
+ bool poll();
private:
/**
diff --git a/src/network/socket_handler.cpp b/src/network/socket_handler.cpp
index e738302..737bbf5 100644
--- a/src/network/socket_handler.cpp
+++ b/src/network/socket_handler.cpp
@@ -66,7 +66,10 @@ void SocketHandler::on_recv()
ssize_t size = ::recv(this->socket, buf, 4096, 0);
if (0 == size)
- this->on_connection_close();
+ {
+ this->on_connection_close();
+ this->close();
+ }
else if (-1 == static_cast<ssize_t>(size))
throw std::runtime_error("Error reading from socket");
else