Trait tk_sendfile::Destination [] [src]

pub trait Destination: Write + Send {
    fn write_file<O: FileOpener>(&mut self,
                                 file: &mut Sendfile<O>)
                                 -> Result<usize, Error>; fn poll_write(&mut self) -> Async<()>; }

A trait that represents anything that file can be sent to

The trait is implemented for TcpStream right away but you might want to implement your own thing, for example to prepend the data with file length header

Required Methods

This method does the actual sendfile call

Note: this method is called in other thread

Test to see if this object may be writable

Note that in default implementation (for AsRawFd + Write) we use poll() syscall here explicitly. This may seem wasteful, but it's not for the folowing reasons:

  • It's very cheap syscall as cheap as possible
  • For tokio-core its normal that spurious wake ups happen
  • On a spurious wakeup we transfer socket to disk thread, thread does useless sendfile() call, then transfers socket to the IO thread back and wakes up IO thread. I.e. at least two syscalls of at least as expensive as poll() syscall here.

Implementors