Trait Source
trait Source
An event source that may be registered with Registry.
Types that implement event::Source can be registered with
Registry. Users of Mio should not use the event::Source trait
functions directly. Instead, the equivalent functions on Registry should
be used.
See Registry for more details.
Implementing event::Source
Event sources are always backed by system handles, such as sockets or other
system handles. These event::Sources will be monitored by the system
selector. An implementation of Source will almost always delegates to a
lower level handle. Examples of this are TcpStreams, or the unix only
SourceFd.
Dropping event::Sources
All event::Sources, unless otherwise specified, need to be deregistered
before being dropped for them to not leak resources. This goes against the
normal drop behaviour of types in Rust which cleanup after themselves, e.g.
a File will close itself. However since deregistering needs access to
Registry this cannot be done while being dropped.
Examples
Implementing Source on a struct containing a socket:
use ;
use Source;
use TcpStream;
use io;
#
Required Methods
fn register(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>Register
selfwith the givenRegistryinstance.This function should not be called directly. Use
Registry::registerinstead. Implementors should handle registration by delegating the call to anotherSourcetype.fn reregister(self: &mut Self, registry: &Registry, token: Token, interests: Interest) -> Result<()>Re-register
selfwith the givenRegistryinstance.This function should not be called directly. Use
Registry::reregisterinstead. Implementors should handle re-registration by either delegating the call to anotherSourcetype.fn deregister(self: &mut Self, registry: &Registry) -> Result<()>Deregister
selffrom the givenRegistryinstance.This function should not be called directly. Use
Registry::deregisterinstead. Implementors should handle deregistration by delegating the call to anotherSourcetype.
Implementors
impl Source for TcpListenerimpl Source for TcpStreamimpl<'a> Source for SourceFd<'a>impl Source for UdpSocketimpl Source for UnixDatagramimpl Source for UnixListenerimpl Source for Senderimpl<T> Source for Box<T>impl Source for Receiverimpl Source for UnixStream