From: Ian Jackson Date: Mon, 17 May 2021 13:47:17 +0000 (+0100) Subject: timedfd: Provide TimedFdWriter too X-Git-Tag: otter-0.6.0~220 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=253ff25d88c6582fc55956f55eb4ad603465ffcb;p=otter.git timedfd: Provide TimedFdWriter too Signed-off-by: Ian Jackson --- diff --git a/src/timedfd.rs b/src/timedfd.rs index c16aa136..91eed394 100644 --- a/src/timedfd.rs +++ b/src/timedfd.rs @@ -25,11 +25,16 @@ pub trait TimedFdReadWrite { } pub type TimedFdReader = TimedFd; +pub type TimedFdWriter = TimedFd; #[derive(Debug,Copy,Clone)] pub struct TimedFdRead; impl TimedFdReadWrite for TimedFdRead { const INTEREST : mio::Interest = mio::Interest::READABLE; } +#[derive(Debug,Copy,Clone)] pub struct TimedFdWrite; +impl TimedFdReadWrite for TimedFdWrite { + const INTEREST : mio::Interest = mio::Interest::WRITABLE; +} pub struct Fd(RawFd); impl Fd { @@ -128,6 +133,16 @@ impl Read for TimedFd { } } +impl Write for TimedFd { + #[throws(io::Error)] + fn write(&mut self, buf: &[u8]) -> usize { + self.rw(|fd| unistd::write(fd, buf))? + } + #[throws(io::Error)] + fn flush(&mut self) { + } +} + impl Drop for Fd { fn drop(&mut self) { let fd = self.extract_raw_fd();