event/Loop: move code to Wait()
This commit is contained in:
parent
1473d8474f
commit
b611b1824a
@ -184,6 +184,22 @@ ExportTimeoutMS(Event::Duration timeout)
|
|||||||
: -1;
|
: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
EventLoop::Wait(Event::Duration timeout) noexcept
|
||||||
|
{
|
||||||
|
const auto poll_result =
|
||||||
|
poll_group.ReadEvents(ExportTimeoutMS(timeout));
|
||||||
|
|
||||||
|
ready_sockets.clear();
|
||||||
|
for (size_t i = 0; i < poll_result.GetSize(); ++i) {
|
||||||
|
auto &s = *(SocketEvent *)poll_result.GetObject(i);
|
||||||
|
s.SetReadyFlags(poll_result.GetEvents(i));
|
||||||
|
ready_sockets.push_back(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return poll_result.GetSize() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
EventLoop::Run() noexcept
|
EventLoop::Run() noexcept
|
||||||
{
|
{
|
||||||
@ -257,15 +273,7 @@ EventLoop::Run() noexcept
|
|||||||
|
|
||||||
/* wait for new event */
|
/* wait for new event */
|
||||||
|
|
||||||
const auto poll_result =
|
Wait(timeout);
|
||||||
poll_group.ReadEvents(ExportTimeoutMS(timeout));
|
|
||||||
|
|
||||||
ready_sockets.clear();
|
|
||||||
for (size_t i = 0; i < poll_result.GetSize(); ++i) {
|
|
||||||
auto &s = *(SocketEvent *)poll_result.GetObject(i);
|
|
||||||
s.SetReadyFlags(poll_result.GetEvents(i));
|
|
||||||
ready_sockets.push_back(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
now = std::chrono::steady_clock::now();
|
now = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
@ -258,6 +258,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
Event::Duration HandleTimers() noexcept;
|
Event::Duration HandleTimers() noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call epoll_wait() and pass all returned events to
|
||||||
|
* SocketEvent::SetReadyFlags().
|
||||||
|
*
|
||||||
|
* @return true if one or more sockets have become ready
|
||||||
|
*/
|
||||||
|
bool Wait(Event::Duration timeout) noexcept;
|
||||||
|
|
||||||
#ifdef HAVE_THREADED_EVENT_LOOP
|
#ifdef HAVE_THREADED_EVENT_LOOP
|
||||||
void OnSocketReady(unsigned flags) noexcept;
|
void OnSocketReady(unsigned flags) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user