pub struct UnixListener<S> { /* private fields */ }target_family="unix" only.Expand description
A Unix (domain) socket server, listening for incoming connections once served
using one of the serve methods such as UnixListener::serve.
Note that the underlying socket (file) is only cleaned up
by this listener’s Drop implementation if the listener
was created using the bind_path constructor. Otherwise
it is assumed that the creator of this listener is in charge
of that cleanup.
Implementations§
Source§impl UnixListener<()>
impl UnixListener<()>
Sourcepub fn build() -> UnixListenerBuilder<()>
pub fn build() -> UnixListenerBuilder<()>
Create a new UnixListenerBuilder without a state,
which can be used to configure a UnixListener.
Sourcepub fn build_with_state<S>(state: S) -> UnixListenerBuilder<S>
pub fn build_with_state<S>(state: S) -> UnixListenerBuilder<S>
Create a new UnixListenerBuilder with the given state,
which can be used to configure a UnixListener.
Sourcepub async fn bind_path(path: impl AsRef<Path>) -> Result<Self, Error>
pub async fn bind_path(path: impl AsRef<Path>) -> Result<Self, Error>
Creates a new UnixListener, which will be bound to the specified path.
The returned listener is ready for accepting connections.
Sourcepub fn bind_socket(socket: Socket) -> Result<Self, Error>
pub fn bind_socket(socket: Socket) -> Result<Self, Error>
Creates a new UnixListener, which will be bound to the specified socket.
The returned listener is ready for accepting connections.
Sourcepub async fn bind_socket_opts(opts: SocketOptions) -> Result<Self, BoxError>
Available on Android or Fuchsia or Linux only.
pub async fn bind_socket_opts(opts: SocketOptions) -> Result<Self, BoxError>
Creates a new TcpListener, which will be bound to the specified (interface) device name.
The returned listener is ready for accepting connections.
Source§impl<S> UnixListener<S>
impl<S> UnixListener<S>
Sourcepub fn local_addr(&self) -> Result<SocketAddr>
pub fn local_addr(&self) -> Result<SocketAddr>
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.
Source§impl UnixListener<()>
impl UnixListener<()>
Sourcepub fn with_state<S>(self, state: S) -> UnixListener<S>
pub fn with_state<S>(self, state: S) -> UnixListener<S>
Define the TcpListener’s state after it was created, useful in case it wasn’t built using the builder.
Source§impl<State> UnixListener<State>
impl<State> UnixListener<State>
Sourcepub async fn accept(&self) -> Result<(UnixStream, UnixSocketAddress)>
pub async fn accept(&self) -> Result<(UnixStream, UnixSocketAddress)>
Accept a single connection from this listener, what you can do with whatever you want.
Sourcepub async fn serve<S>(self, service: S)where
S: Service<State, UnixStream>,
pub async fn serve<S>(self, service: S)where
S: Service<State, UnixStream>,
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.
Sourcepub async fn serve_graceful<S>(self, guard: ShutdownGuard, service: S)where
S: Service<State, UnixStream>,
pub async fn serve_graceful<S>(self, guard: ShutdownGuard, service: S)where
S: Service<State, UnixStream>,
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.