diff --git a/src/io/split.rs b/src/io/split.rs index fe8071de7..fca1f23fe 100644 --- a/src/io/split.rs +++ b/src/io/split.rs @@ -1,8 +1,11 @@ use std::cell::RefCell; use std::io::{self, Read, Write}; +use futures::Async; use futures::task::TaskRc; +use io::Io; + /// The readable half of an object returned from `Io::split`. pub struct ReadHalf { handle: TaskRc>, @@ -13,11 +16,27 @@ pub struct WriteHalf { handle: TaskRc>, } -pub fn split(t: T) -> (ReadHalf, WriteHalf) { +pub fn split(t: T) -> (ReadHalf, WriteHalf) { let rc = TaskRc::new(RefCell::new(t)); (ReadHalf { handle: rc.clone() }, WriteHalf { handle: rc }) } +impl ReadHalf { + /// Calls the underlying `poll_read` function on this handling, testing to + /// see if it's ready to be read from. + pub fn poll_read(&mut self) -> Async<()> { + self.handle.with(|t| t.borrow_mut().poll_read()) + } +} + +impl WriteHalf { + /// Calls the underlying `poll_write` function on this handling, testing to + /// see if it's ready to be written to. + pub fn poll_write(&mut self) -> Async<()> { + self.handle.with(|t| t.borrow_mut().poll_write()) + } +} + impl Read for ReadHalf { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.handle.with(|t| t.borrow_mut().read(buf))