pub struct Listener<'n, 'a: 'n> { /* private fields */ }Expand description
A TCP listener, held as a capability.
Accepting hands over authority - each accepted connection is its own capability - so accepting requires the listener’s WRITE right. A read-only listener capability can be held and inspected and cannot take connections.
Implementations§
Source§impl<'n, 'a: 'n> Listener<'n, 'a>
impl<'n, 'a: 'n> Listener<'n, 'a>
Sourcepub fn accept(&mut self) -> Result<Option<Conn<'_, 'n, 'a>>, Error>
pub fn accept(&mut self) -> Result<Option<Conn<'_, 'n, 'a>>, Error>
Take the next connection, if one is waiting.
Ok(None) means nobody has connected yet. That is an ordinary poll result, not an error,
so a server loops on it - and loops rather than blocking so it can still notice its own
deadline, its operator, or a request on its endpoint.
Blocks up to NET_SECS per call. Authority: this listener’s WRITE right, because
accepting hands over authority.
§Errors
Error::PermissionDenied if the capability lacks WRITE; Error::Revoked if
net-stack restarted, in which case listen again - the port went with it.
Sourcepub fn close(self) -> Result<(), Error>
pub fn close(self) -> Result<(), Error>
Stop listening and release the port.
Consumes the listener. Dropping one also releases it, but a Drop cannot report a failure -
and a port that was not released refuses the next listen on it, which is a confusing way to
find out. Close explicitly where it matters.
Sourcepub fn take_held(&mut self) -> Option<Message>
pub fn take_held(&mut self) -> Option<Message>
Take one message that arrived during an operation and was NOT the reply. See
Socket::take_held.