Struct Listener

Source
pub struct Listener {
    pub addr: Option<IpAddr>,
    pub port: u16,
    pub proto: Protocol,
    handle: JoinHandle<()>,
}
Expand description

A links redirector listener.

Listens for incoming network connections on a specified address using a specified protocol in an async task in the background. On drop, the async task is aborted in order to stop listening.

Fields§

§addr: Option<IpAddr>

The address this listener will listen on. No address indicates that this listener will accept all traffic on any address (IPv4 and IPv6), 0.0.0.0 means any IPv4 address (but not IPv6), [::] means any IPv6 address (but not IPv4).

§port: u16

The port this listener will listen on. Currently, this is a TCP port, but may in the future also additionally indicate a UDP port.

§proto: Protocol

The protocol of the acceptor/handler this listener uses to process requests

§handle: JoinHandle<()>

Implementations§

Source§

impl Listener

Source

pub async fn new( addr: Option<IpAddr>, port: Option<u16>, acceptor: &'static impl Acceptor<TcpStream>, ) -> Result<Self, IoError>

Create a new Listener on the specified address, which will use the specified acceptor to accept incoming connections. If no address is specified, the listener will listen on all IPv4 and IPv6 addresses. Address 0.0.0.0 can be used to listen on all IPv4 (but not IPv6) addresses, and address [::] can be used to listen on all IPv6 (but not IPv4) addresses. If the port is not specified, the protocol’s default port will be used (see Protocol for details).

Note: Support for dual stack sockets (IPv4 and IPv6 in one socket, available in links via an empty address) is not universal on all platforms (such as some BSDs). On those platforms, an empty address and [::] will behave the same, i.e. an empty address will only listen on IPv6, not IPv4. To get the desired result (IPv4 and IPv6), you must use two listeners, one listening on 0.0.0.0 and the other on [::].

§Drop

When dropped, a listener will wait until its internal task is fully cancelled, which can take some time to complete. Dropping a listener should therefore be considered blocking, and only done in synchronous contexts or via the spawn_blocking function. Additionally, because the drop function blocks its thread until the async runtime completes the cancellation of the task in the background, a listener requires more than one thread to drop, and can not successfully be dropped inside of a single-threaded tokio runtime (the entire program will block indefinitely).

§Errors

This function returns an error if it can not set up the listening socket.

Source

pub const fn listen_address(&self) -> ListenAddress

Get the ListenAddress of this listener

Trait Implementations§

Source§

impl Debug for Listener

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Listener

Source§

fn drop(&mut self)

Cancel the task responsible for listening

§Blocking

This functions blocks the current thread until the task is fully aborted. Additionally, if used in the context of a single-threaded tokio runtime, this function can completely block the entire program.

Auto Trait Implementations§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T