Skip to main content

ListenerSpec

Struct ListenerSpec 

Source
pub struct ListenerSpec { /* private fields */ }
Expand description

One listener of a server.

use net_io::{ListenerSpec, Limits};
let spec = ListenerSpec::tcp("127.0.0.1:0")
    .name("admin")
    .limits(Limits::builder().max_per_listener(10).build()?);

Implementations§

Source§

impl ListenerSpec

Source

pub fn tcp<A: ToSocketAddrs>(addr: A) -> ListenerSpec

A TCP listener on addr (resolved now; a failure is reported by build).

Source

pub fn lockdown_allowed(self, on: bool) -> ListenerSpec

Keeps admitting under ControlState::Lockdown, for the listener an operator comes in through while everything else is refused.

Source

pub fn tcp_with<A: ToSocketAddrs>( addr: A, options: ListenOptions, ) -> ListenerSpec

A TCP listener with explicit options (their backlog wins over the limits’).

Source

pub fn udp<A: ToSocketAddrs>(addr: A, options: UdpOptions) -> ListenerSpec

Available on crate feature udp only.

A UDP socket served by the UdpSession that ServerBuilder::udp_sessions makes (feature udp). A thread of its own reads it, with the door and a stop like any listener, and the socket’s budgets and amplification guard apply.

use net_io::{ListenerSpec, UdpOptions};
let spec = ListenerSpec::udp("0.0.0.0:5353", UdpOptions::new());
Source

pub fn unix(path: impl Into<PathBuf>, options: LocalOptions) -> ListenerSpec

A Unix domain socket listener at path (feature local; on Windows, AF_UNIX, where NTFS ACLs replace options’ mode and owner). The socket file gets options’ mode and owner before it listens, and is removed at shutdown if it is still the file this server created. Connections carry Transport::Unix, the peer’s credentials, and no IP address: the per-source cap does not apply, and a BlockingHandler receives them as a TcpConnection whose peer_addr is unspecified. With proxy, every peer is trusted: the socket file’s permissions decide who may connect.

use net_io::{ListenerSpec, LocalOptions};
let spec = ListenerSpec::unix("/run/myapp/api.sock", LocalOptions::new().group_access(33));
Source

pub fn adopt(handle: ListenerHandle) -> ListenerSpec

A listener this process was given: inherited from systemd or a FastCGI manager, received in a hand-off, or released by another server. Its name is the handle’s unless ListenerSpec::name sets one. The socket is not bound again; options set at bind time stay as they are, and the backlog is reported as unknown. An adopted Unix socket’s file is left in place at shutdown (the next bind removes it as stale).

use net_io::ListenerSpec;
for inherited in net_io::systemd()? {
    let spec = ListenerSpec::adopt(inherited.handle);
}
Source

pub fn name(self, name: &str) -> ListenerSpec

A name (up to 64 bytes) for events and hand-off.

Source

pub fn limits(self, limits: Limits) -> ListenerSpec

Per-listener caps and deadlines; values set here override the server’s.

Source

pub fn proxy(self, mode: ProxyMode) -> ListenerSpec

Requires a PROXY protocol header on every connection (feature proxy). Peers outside the trusted proxies are closed before any byte is read.

use net_io::{ListenerSpec, ProxyMode, ProxyVersions};
let spec = ListenerSpec::tcp("127.0.0.1:0").proxy(ProxyMode::Required { versions: ProxyVersions::Both });
Source

pub fn tls(self, on: bool) -> ListenerSpec

Serves TLS on this listener through the builder’s acceptor (ServerBuilder::tls, feature tls).

Source

pub fn trusted_proxies(self, proxies: TrustedProxies) -> ListenerSpec

The proxies trusted on this listener, instead of the server’s list.

Trait Implementations§

Source§

impl Debug for ListenerSpec

Source§

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

Formats the value using the given formatter. Read more

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.