event/SocketMonitor: wake up the event loop after flag change

This commit is contained in:
Max Kellermann 2013-01-30 15:01:34 +01:00
parent 18e429a87e
commit be3d2188d6
2 changed files with 14 additions and 0 deletions

View File

@ -159,3 +159,9 @@ SocketMonitor::Write(const void *data, size_t length)
return send(Get(), (const char *)data, length, flags); return send(Get(), (const char *)data, length, flags);
} }
void
SocketMonitor::CommitEventFlags()
{
loop.WakeUp();
}

View File

@ -89,26 +89,32 @@ public:
void Schedule(unsigned flags) { void Schedule(unsigned flags) {
poll.events = flags; poll.events = flags;
poll.revents &= flags; poll.revents &= flags;
CommitEventFlags();
} }
void Cancel() { void Cancel() {
poll.events = 0; poll.events = 0;
CommitEventFlags();
} }
void ScheduleRead() { void ScheduleRead() {
poll.events |= READ|HANGUP|ERROR; poll.events |= READ|HANGUP|ERROR;
CommitEventFlags();
} }
void ScheduleWrite() { void ScheduleWrite() {
poll.events |= WRITE; poll.events |= WRITE;
CommitEventFlags();
} }
void CancelRead() { void CancelRead() {
poll.events &= ~(READ|HANGUP|ERROR); poll.events &= ~(READ|HANGUP|ERROR);
CommitEventFlags();
} }
void CancelWrite() { void CancelWrite() {
poll.events &= ~WRITE; poll.events &= ~WRITE;
CommitEventFlags();
} }
ssize_t Read(void *data, size_t length); ssize_t Read(void *data, size_t length);
@ -128,6 +134,8 @@ public:
gpointer user_data); gpointer user_data);
private: private:
void CommitEventFlags();
bool Check() const { bool Check() const {
return (poll.revents & poll.events) != 0; return (poll.revents & poll.events) != 0;
} }