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
fn write_file<O: FileOpener>(&mut self,
file: &mut Sendfile<O>)
-> Result<usize, Error>
file: &mut Sendfile<O>)
-> Result<usize, Error>
This method does the actual sendfile call
Note: this method is called in other thread
fn poll_write(&mut self) -> Async<()>
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 aspoll()
syscall here.