event/PollGroup: ReadEvents() returns PollResult
This commit is contained in:
parent
0ecc3394c3
commit
1473d8474f
@ -257,8 +257,8 @@ EventLoop::Run() noexcept
|
||||
|
||||
/* wait for new event */
|
||||
|
||||
PollResult poll_result;
|
||||
poll_group.ReadEvents(poll_result, ExportTimeoutMS(timeout));
|
||||
const auto poll_result =
|
||||
poll_group.ReadEvents(ExportTimeoutMS(timeout));
|
||||
|
||||
ready_sockets.clear();
|
||||
for (size_t i = 0; i < poll_result.GetSize(); ++i) {
|
||||
|
@ -25,19 +25,16 @@
|
||||
#ifdef _WIN32
|
||||
|
||||
#include "PollGroupWinSelect.hxx"
|
||||
typedef PollResultGeneric PollResult;
|
||||
typedef PollGroupWinSelect PollGroup;
|
||||
|
||||
#elif defined(USE_EPOLL)
|
||||
|
||||
#include "PollGroupEpoll.hxx"
|
||||
typedef PollResultEpoll PollResult;
|
||||
typedef PollGroupEpoll PollGroup;
|
||||
|
||||
#else
|
||||
|
||||
#include "PollGroupPoll.hxx"
|
||||
typedef PollResultGeneric PollResult;
|
||||
typedef PollGroupPoll PollGroup;
|
||||
|
||||
#endif
|
||||
|
@ -61,10 +61,12 @@ public:
|
||||
|
||||
PollGroupEpoll() = default;
|
||||
|
||||
void ReadEvents(PollResultEpoll &result, int timeout_ms) noexcept {
|
||||
auto ReadEvents(int timeout_ms) noexcept {
|
||||
PollResultEpoll result;
|
||||
int ret = epoll.Wait(result.events.data(), result.events.size(),
|
||||
timeout_ms);
|
||||
result.n_events = std::max(0, ret);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Add(int fd, unsigned events, void *obj) noexcept {
|
||||
|
@ -71,12 +71,13 @@ PollGroupPoll::Remove(int fd) noexcept
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PollGroupPoll::ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept
|
||||
PollResultGeneric
|
||||
PollGroupPoll::ReadEvents(int timeout_ms) noexcept
|
||||
{
|
||||
int n = poll(poll_events.empty() ? nullptr : &poll_events[0],
|
||||
poll_events.size(), timeout_ms);
|
||||
|
||||
PollResultGeneric result;
|
||||
for (size_t i = 0; n > 0 && i < poll_events.size(); ++i) {
|
||||
const auto &e = poll_events[i];
|
||||
if (e.revents != 0) {
|
||||
@ -84,4 +85,6 @@ PollGroupPoll::ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public:
|
||||
PollGroupPoll() noexcept;
|
||||
~PollGroupPoll() noexcept;
|
||||
|
||||
void ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept;
|
||||
PollResultGeneric ReadEvents(int timeout_ms) noexcept;
|
||||
bool Add(int fd, unsigned events, void *obj) noexcept;
|
||||
bool Modify(int fd, unsigned events, void *obj) noexcept;
|
||||
bool Remove(int fd) noexcept;
|
||||
|
@ -115,9 +115,8 @@ PollGroupWinSelect::Remove(SOCKET fd) noexcept
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PollGroupWinSelect::ReadEvents(PollResultGeneric &result,
|
||||
int timeout_ms) noexcept
|
||||
PollResultGeneric
|
||||
PollGroupWinSelect::ReadEvents(int timeout_ms) noexcept
|
||||
{
|
||||
bool use_sleep = event_set[EVENT_READ].IsEmpty() &&
|
||||
event_set[EVENT_WRITE].IsEmpty();
|
||||
@ -143,8 +142,9 @@ PollGroupWinSelect::ReadEvents(PollResultGeneric &result,
|
||||
except_set.GetPtr(),
|
||||
timeout_ms < 0 ? nullptr : &tv);
|
||||
|
||||
PollResultGeneric result;
|
||||
if (ret == 0 || ret == SOCKET_ERROR)
|
||||
return;
|
||||
return result;
|
||||
|
||||
for (const auto i : read_set)
|
||||
items[i].events |= READ;
|
||||
@ -160,4 +160,6 @@ PollGroupWinSelect::ReadEvents(PollResultGeneric &result,
|
||||
result.Add(i.second.events, i.second.obj);
|
||||
i.second.events = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public:
|
||||
PollGroupWinSelect() noexcept;
|
||||
~PollGroupWinSelect() noexcept;
|
||||
|
||||
void ReadEvents(PollResultGeneric &result, int timeout_ms) noexcept;
|
||||
PollResultGeneric ReadEvents(int timeout_ms) noexcept;
|
||||
bool Add(SOCKET fd, unsigned events, void *obj) noexcept;
|
||||
bool Modify(SOCKET fd, unsigned events, void *obj) noexcept;
|
||||
bool Remove(SOCKET fd) noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user