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(exec: Executor) -> TcpListenerBuilder
pub fn build(exec: Executor) -> TcpListenerBuilder
Create a new TcpListenerBuilder without a state,
which can be used to configure a TcpListener.
pub async fn bind_address<A>(
addr: A,
exec: Executor,
) -> Result<TcpListener, Box<dyn Error + Send + Sync>>where
A: TryInto<SocketAddress>,
<A as TryInto<SocketAddress>>::Error: Into<Box<dyn Error + Send + Sync>>,
pub async fn bind_address<A>(
addr: A,
exec: Executor,
) -> Result<TcpListener, Box<dyn Error + Send + Sync>>where
A: TryInto<SocketAddress>,
<A as TryInto<SocketAddress>>::Error: Into<Box<dyn Error + Send + Sync>>,
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,
exec: Executor,
) -> Result<TcpListener, Box<dyn Error + Send + Sync>>
pub async fn bind_socket( socket: Socket, exec: Executor, ) -> Result<TcpListener, Box<dyn Error + Send + Sync>>
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,
exec: Executor,
) -> Result<TcpListener, Box<dyn Error + Send + Sync>>
pub async fn bind_device<N>( name: N, exec: Executor, ) -> Result<TcpListener, Box<dyn Error + Send + Sync>>
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.
pub fn ttl(&self) -> Result<u32, Error>
pub fn ttl(&self) -> Result<u32, Error>
Gets the value of the IP_TTL option for this socket.
For more information about this option, see set_ttl.
pub fn set_ttl(&self, ttl: u32) -> Result<(), Error>
pub fn set_ttl(&self, ttl: u32) -> Result<(), Error>
Sets the value for the IP_TTL option on this socket.
This value sets the time-to-live field that is used in every packet sent from this socket.
pub fn into_std(self) -> Result<TcpListener, Error>
pub fn into_std(self) -> Result<TcpListener, Error>
Converts this TcpListener into a std::net::TcpListener.
The returned listener will be in blocking mode. To convert it back
to non-blocking for use with Rama, use TryFrom<std::net::TcpListener>.
This is useful for zero-downtime restarts where listener file descriptors
need to be passed between processes via SCM_RIGHTS.
pub fn into_inner(self) -> TcpListener
pub fn into_inner(self) -> TcpListener
Consumes this TcpListener and returns the inner [tokio::net::TcpListener].
pub fn from_tokio_tcp_listener( listener: TcpListener, exec: Executor, ) -> TcpListener
pub fn try_from_socket( socket: Socket, exec: Executor, ) -> Result<TcpListener, Error>
pub fn try_from_std_tcp_listener( listener: TcpListener, exec: Executor, ) -> Result<TcpListener, Error>
§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 listener will spawn a task in which the inner service will
handle the incomming connection. Cconnections will be served
gracefully if the TcpListener is configured with a graceful Executor.
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 AsFd for TcpListener
impl AsFd for TcpListener
§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Auto Trait Implementations§
impl !Freeze for TcpListener
impl RefUnwindSafe for TcpListener
impl Send for TcpListener
impl Sync for TcpListener
impl Unpin for TcpListener
impl UnsafeUnpin 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§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