pub struct Listener { /* private fields */ }
Expand description
A network listener.
Listener
is a abstract listener that works in conjunction with Stream
, providing the ability to listen on
arbitrary addresses and accept new streams of that address family.
§Connection-oriented vs connectionless listeners
For listeners on connection-oriented address families (e.g. TCP, Unix domain sockets in stream mode), the listener
will listen for an accept new connections in the typical fashion. However, for connectionless address families
(e.g. UDP, Unix domain sockets in datagram mode), there is no concept of a “connection” and so nothing to be
continually “accepted”. Instead, Listener
will emit a single Stream
that can be used to send and receive data
from multiple remote peers.
§Missing
- Ability to configure
Listener
to emit multiple streams for connectionless address families, allowing for load balancing. (Only possible for UDP via SO_REUSEPORT, as UDS does not support SO_REUSEPORT.)
Implementations§
Source§impl Listener
impl Listener
Sourcepub async fn from_listen_address(
listen_address: ListenAddress,
) -> Result<Self, ListenerError>
pub async fn from_listen_address( listen_address: ListenAddress, ) -> Result<Self, ListenerError>
Creates a new Listener
from the given listen address.
§Errors
If the listen address cannot be bound, or if the listener cannot be configured correctly, an error is returned.
Sourcepub fn listen_address(&self) -> &ListenAddress
pub fn listen_address(&self) -> &ListenAddress
Gets a reference to the listen address.
Sourcepub async fn accept(&mut self) -> Result<Stream, ListenerError>
pub async fn accept(&mut self) -> Result<Stream, ListenerError>
Accepts a new stream from the listener.
For connection-oriented address families, this will accept a new connection and return a Stream
that is bound
to that remote peer. For connectionless address families, this will return a single Stream
that will receive
from multiple remote peers, and no further streams will be emitted.
§Errors
If the listener fails to accept a new stream, or if the accepted stream cannot be configured correctly, an error is returned.
Auto Trait Implementations§
impl !Freeze for Listener
impl RefUnwindSafe for Listener
impl Send for Listener
impl Sync for Listener
impl Unpin for Listener
impl UnwindSafe for Listener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read moreSource§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more