summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/network')
-rw-r--r--src/network/poller.cpp34
-rw-r--r--src/network/poller.hpp10
2 files changed, 40 insertions, 4 deletions
diff --git a/src/network/poller.cpp b/src/network/poller.cpp
index c7d9eb2..7ab8bc3 100644
--- a/src/network/poller.cpp
+++ b/src/network/poller.cpp
@@ -59,12 +59,39 @@ void Poller::remove_socket_handler(const socket_t socket)
}
}
+void Poller::watch_send_events(const SocketHandler* const socket_handler)
+{
+#if POLLER == POLL
+ for (size_t i = 0; i <= this->nfds; ++i)
+ {
+ if (this->fds[i].fd == socket_handler->get_socket())
+ {
+ this->fds[i].events = POLLIN|POLLOUT;
+ return;
+ }
+ }
+#endif
+ throw std::runtime_error("Cannot watch a non-registered socket for send events");
+}
+
+void Poller::stop_watching_send_events(const SocketHandler* const socket_handler)
+{
+#if POLLER == POLL
+ for (size_t i = 0; i <= this->nfds; ++i)
+ {
+ if (this->fds[i].fd == socket_handler->get_socket())
+ {
+ this->fds[i].events = POLLIN;
+ return;
+ }
+ }
+#endif
+ throw std::runtime_error("Cannot watch a non-registered socket for send events");
+}
+
void Poller::poll()
{
#if POLLER == POLL
- std::cout << "Polling:" << std::endl;
- for (size_t i = 0; i < this->nfds; ++i)
- std::cout << "pollfd[" << i << "]: (" << this->fds[i].fd << ")" << std::endl;
int res = ::poll(this->fds, this->nfds, -1);
if (res < 0)
{
@@ -93,4 +120,3 @@ void Poller::poll()
}
#endif
}
-
diff --git a/src/network/poller.hpp b/src/network/poller.hpp
index 46a184e..64e78e4 100644
--- a/src/network/poller.hpp
+++ b/src/network/poller.hpp
@@ -45,6 +45,16 @@ public:
*/
void remove_socket_handler(const socket_t socket);
/**
+ * Signal the poller that he needs to watch for send events for the given
+ * SocketHandler.
+ */
+ void watch_send_events(const SocketHandler* const socket_handler);
+ /**
+ * Signal the poller that he needs to stop watching for send events for
+ * this SocketHandler.
+ */
+ void stop_watching_send_events(const SocketHandler* const socket_handler);
+ /**
* Wait for all watched events, and call the SocketHandlers' callbacks
* when one is ready.
*/