Struct TcpListener
pub struct TcpListener { /* private fields */ }
Expand description
A TCP socket server, listening for incoming connections once served
using one of the serve
methods such as TcpListener::serve
.
Implementations§
§impl TcpListener
impl TcpListener
pub fn build() -> TcpListenerBuilder
pub fn build() -> TcpListenerBuilder
Create a new TcpListenerBuilder
without a state,
which can be used to configure a TcpListener
.
pub async fn bind_address<A>(
addr: A,
) -> Result<TcpListener, Box<dyn Error + Sync + Send>>where
A: TryInto<SocketAddress>,
<A as TryInto<SocketAddress>>::Error: Into<Box<dyn Error + Sync + Send>>,
pub async fn bind_address<A>(
addr: A,
) -> Result<TcpListener, Box<dyn Error + Sync + Send>>where
A: TryInto<SocketAddress>,
<A as TryInto<SocketAddress>>::Error: Into<Box<dyn Error + Sync + Send>>,
Creates a new TcpListener, which will be bound to the specified (socket) address.
The returned listener is ready for accepting connections.
Binding with a port number of 0 will request that the OS assigns a port
to this listener. The port allocated can be queried via the local_addr
method.
pub async fn bind_socket(
socket: Socket,
) -> Result<TcpListener, Box<dyn Error + Sync + Send>>
pub async fn bind_socket( socket: Socket, ) -> Result<TcpListener, Box<dyn Error + Sync + Send>>
Creates a new TcpListener, which will be bound to the specified socket.
The returned listener is ready for accepting connections.
pub async fn bind_device<N>(
name: N,
) -> Result<TcpListener, Box<dyn Error + Sync + Send>>
pub async fn bind_device<N>( name: N, ) -> Result<TcpListener, Box<dyn Error + Sync + Send>>
Creates a new TcpListener, which will be bound to the specified (interface) device name.
The returned listener is ready for accepting connections.
§impl TcpListener
impl TcpListener
pub fn local_addr(&self) -> Result<SocketAddr, Error>
pub fn local_addr(&self) -> Result<SocketAddr, Error>
Returns the local address that this listener is bound to.
This can be useful, for example, when binding to port 0 to figure out which port was actually bound.
§impl TcpListener
impl TcpListener
pub async fn accept(&self) -> Result<(TcpStream, SocketAddress), Error>
pub async fn accept(&self) -> Result<(TcpStream, SocketAddress), Error>
Accept a single connection from this listener, what you can do with whatever you want.
pub async fn serve<S>(self, service: S)
pub async fn serve<S>(self, service: S)
Serve connections from this listener with the given service.
This method will block the current listener for each incoming connection, the underlying service can choose to spawn a task to handle the accepted stream.
pub async fn serve_graceful<S>(self, guard: ShutdownGuard, service: S)
pub async fn serve_graceful<S>(self, guard: ShutdownGuard, service: S)
Serve gracefully connections from this listener with the given service.
This method does the same as Self::serve
but it
will respect the given rama_core::graceful::ShutdownGuard
, and also pass
it to the service.
Trait Implementations§
§impl Acceptor for TcpListener
impl Acceptor for TcpListener
§fn local_addr(&self) -> Result<SocketAddress, Error>
fn local_addr(&self) -> Result<SocketAddress, Error>
§async fn accept(
self,
) -> Result<(<TcpListener as Acceptor>::Stream, SocketAddress), Error>
async fn accept( self, ) -> Result<(<TcpListener as Acceptor>::Stream, SocketAddress), Error>
§impl Debug for TcpListener
impl Debug for TcpListener
§impl From<TcpListener> for TcpListener
impl From<TcpListener> for TcpListener
§fn from(value: TcpListener) -> TcpListener
fn from(value: TcpListener) -> TcpListener
§impl TryFrom<Socket> for TcpListener
impl TryFrom<Socket> for TcpListener
§impl TryFrom<TcpListener> for TcpListener
impl TryFrom<TcpListener> for TcpListener
§fn try_from(
value: TcpListener,
) -> Result<TcpListener, <TcpListener as TryFrom<TcpListener>>::Error>
fn try_from( value: TcpListener, ) -> Result<TcpListener, <TcpListener as TryFrom<TcpListener>>::Error>
Auto Trait Implementations§
impl !Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnwindSafe for TcpListener
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more