Commit f182d377 authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Expose socket count and internal event handling

parent 2cae44fc
...@@ -167,6 +167,12 @@ public: ...@@ -167,6 +167,12 @@ public:
/// Get the next id to create a new datagram handle /// Get the next id to create a new datagram handle
int64_t next_endpoint_id(); int64_t next_endpoint_id();
/// Returns the number of socket handlers.
size_t num_socket_handlers() const noexcept;
/// Run all pending events generated from calls to `add` or `del`.
void handle_internal_events();
private: private:
/// Calls `epoll`, `kqueue`, or `poll` with or without blocking. /// Calls `epoll`, `kqueue`, or `poll` with or without blocking.
bool poll_once_impl(bool block); bool poll_once_impl(bool block);
......
...@@ -205,10 +205,7 @@ namespace network { ...@@ -205,10 +205,7 @@ namespace network {
auto fd = ptr ? ptr->fd() : pipe_.first; auto fd = ptr ? ptr->fd() : pipe_.first;
handle_socket_event(fd, static_cast<int>(iter->events), ptr); handle_socket_event(fd, static_cast<int>(iter->events), ptr);
} }
for (auto& me : events_) { handle_internal_events();
handle(me);
}
events_.clear();
return true; return true;
} }
} }
...@@ -285,6 +282,10 @@ namespace network { ...@@ -285,6 +282,10 @@ namespace network {
} }
} }
size_t default_multiplexer::num_socket_handlers() const noexcept {
return shadow_;
}
#else // CAF_EPOLL_MULTIPLEXER #else // CAF_EPOLL_MULTIPLEXER
// Let's be honest: the API of poll() sucks. When dealing with 1000 sockets // Let's be honest: the API of poll() sucks. When dealing with 1000 sockets
...@@ -383,11 +384,8 @@ namespace network { ...@@ -383,11 +384,8 @@ namespace network {
// operations possible on the socket // operations possible on the socket
handle_socket_event(e.fd, e.mask, e.ptr); handle_socket_event(e.fd, e.mask, e.ptr);
} }
CAF_LOG_DEBUG(CAF_ARG(events_.size()));
poll_res.clear(); poll_res.clear();
for (auto& me : events_) handle_internal_events();
handle(me);
events_.clear();
return true; return true;
} }
} }
...@@ -456,6 +454,10 @@ namespace network { ...@@ -456,6 +454,10 @@ namespace network {
} }
} }
size_t default_multiplexer::num_socket_handlers() const noexcept {
return pollset_.size();
}
#endif // CAF_EPOLL_MULTIPLEXER #endif // CAF_EPOLL_MULTIPLEXER
// -- Helper functions for defining bitmasks of event handlers ----------------- // -- Helper functions for defining bitmasks of event handlers -----------------
...@@ -604,9 +606,7 @@ bool default_multiplexer::poll_once(bool block) { ...@@ -604,9 +606,7 @@ bool default_multiplexer::poll_once(bool block) {
internally_posted_.swap(xs); internally_posted_.swap(xs);
for (auto& ptr : xs) for (auto& ptr : xs)
resume(std::move(ptr)); resume(std::move(ptr));
for (auto& me : events_) handle_internal_events();
handle(me);
events_.clear();
// Try to swap back to internall_posted_ to re-use allocated memory. // Try to swap back to internall_posted_ to re-use allocated memory.
if (internally_posted_.empty()) { if (internally_posted_.empty()) {
xs.swap(internally_posted_); xs.swap(internally_posted_);
...@@ -736,6 +736,13 @@ int64_t default_multiplexer::next_endpoint_id() { ...@@ -736,6 +736,13 @@ int64_t default_multiplexer::next_endpoint_id() {
return servant_ids_++; return servant_ids_++;
} }
void default_multiplexer::handle_internal_events() {
CAF_LOG_TRACE(CAF_ARG2("num-events", events_.size()));
for (auto& e : events_)
handle(e);
events_.clear();
}
// -- Related helper functions ------------------------------------------------- // -- Related helper functions -------------------------------------------------
template <int Family> template <int Family>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment