Skip to main content

Listener

Struct Listener 

Source
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>

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'n, 'a: 'n> Drop for Listener<'n, 'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'n, 'a> Freeze for Listener<'n, 'a>

§

impl<'n, 'a> !RefUnwindSafe for Listener<'n, 'a>

§

impl<'n, 'a> !Send for Listener<'n, 'a>

§

impl<'n, 'a> !Sync for Listener<'n, 'a>

§

impl<'n, 'a> Unpin for Listener<'n, 'a>

§

impl<'n, 'a> UnsafeUnpin for Listener<'n, 'a>

§

impl<'n, 'a> !UnwindSafe for Listener<'n, 'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.