Skip to content

Commit

Permalink
epoll: allow controlling write event notifications for bidirectional I/O
Browse files Browse the repository at this point in the history
For sockets that frequently switch between read/write but can be
readable at any time, add a `notify_writable` method to EventGuard which
re-arms the socket with either EPOLLOUT set or cleared.
When there is writable data in userspace but writing is blocked, the
guard can temporarily enable writable events then disable them when
user code has flushed its buffers, instead of having to manually manage
separate 'writer' sockets.
  • Loading branch information
cbranch authored and vkrasnov committed Jun 16, 2020
1 parent feb1d25 commit e45cf84
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/device/epoll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ impl<'a, H> EventGuard<'a, H> {
unsafe { self.poll.clear_event_by_fd(self.event.fd) };
std::mem::forget(self); // Don't call the regular drop that would enable the event
}

/// Change the event flags to enable or disable notifying when the fd is writable
pub fn notify_writable(&mut self, enabled: bool) {
let flags = if enabled {
EPOLLOUT | EPOLLIN | EPOLLET | EPOLLONESHOT
} else {
EPOLLIN | EPOLLONESHOT
};
self.event.event.events = flags as _;
}
}

pub fn block_signal(signal: c_int) -> Result<sigset_t, String> {
Expand Down

0 comments on commit e45cf84

Please sign in to comment.