event/SocketEvent: allow Schedule() with IMPLICIT_FLAGS

Relax the API (instead of tightening it further like commit
7bc1c9925b tried to do unsuccessfully).
This commit is contained in:
Max Kellermann 2020-12-04 09:14:59 +01:00
parent ad48834469
commit b27e82e4a9
2 changed files with 7 additions and 14 deletions

View File

@ -60,6 +60,9 @@ SocketEvent::Abandon() noexcept
bool
SocketEvent::Schedule(unsigned flags) noexcept
{
if (flags != 0)
flags |= IMPLICIT_FLAGS;
if (flags == GetScheduledFlags())
return true;
@ -94,21 +97,11 @@ SocketEvent::Schedule(unsigned flags) noexcept
return success;
}
void
SocketEvent::ScheduleImplicit() noexcept
{
assert(IsDefined());
assert(scheduled_flags == 0);
scheduled_flags = IMPLICIT_FLAGS;
loop.AddFD(fd.Get(), scheduled_flags, *this);
}
void
SocketEvent::Dispatch() noexcept
{
const unsigned flags = std::exchange(ready_flags, 0) &
(GetScheduledFlags() | IMPLICIT_FLAGS);
GetScheduledFlags();
if (flags != 0)
callback(flags);

View File

@ -165,10 +165,10 @@ public:
/**
* Schedule only the #IMPLICIT_FLAGS without #READ and #WRITE.
* This is not possible with Schedule(), and no other
* ScheduleX()/CancelX() method may be called on this object.
*/
void ScheduleImplicit() noexcept;
void ScheduleImplicit() noexcept {
Schedule(IMPLICIT_FLAGS);
}
bool IsReadPending() const noexcept {
return GetScheduledFlags() & READ;