Skip to main content

ListenerOptions

Struct ListenerOptions 

Source
pub struct ListenerOptions<'n> { /* private fields */ }
Expand description

Server-side builder for local socket listeners, including Listener.

Implementations§

Source§

impl ListenerOptions<'_>

Creation and ownership.

Source

pub fn new() -> Self

Returns a default set of listener options.

Source§

impl<'n> ListenerOptions<'n>

Option setters.

Source

pub fn name(self, name: Name<'n>) -> Self

Sets the name the server will listen on.

Source

pub fn nonblocking(self, nonblocking: ListenerNonblockingMode) -> Self

Selects the nonblocking mode to be used by the listener.

The default value is Neither.

Source

pub fn reclaim_name(self, reclaim_name: bool) -> Self

Sets whether name reclamation is to happen or not.

This is enabled by default.

Source

pub fn try_overwrite(self, try_overwrite: bool) -> Self

Sets whether an attempt to handle AddrInUse errors by overwriting an existing listener (in the same manner as in name reclamation) is to be made or not.

If this is enabled, name reclamation will be performed on behalf of a previous listener, even if it is still running and accepting connections, thereby displacing it from the socket name so that the newly created listener could take its place.

This is disabled by default.

§Platform-specific behavior
§Unix

On Unix, this deletes the socket file if an AddrInUse error is encountered. The previous listener, if it is still listening on its socket, is not (and in fact cannot be) notified of this in any way. Note that, by default, this will spin for an unbounded amount of time if there is contention – set max_spin_time if this is undesirable.

The deletion suffers from an unavoidable TOCTOU race between the AddrInUse error being observed and the socket file being deleted, since another process may replace the socket file with a different file, causing Interprocess to delete that file instead. Note that this generally has no inadvertent privilege escalation implications, as the privileges required for renaming a file are the same as the ones required for deleting it, but the behavior may still be surprising in this (admittedly rather artificial) edge case.

§Windows

Does nothing (meaning the error goes unhandled), as named pipes cannot be overwritten.

Source

pub fn max_spin_time(self, max_spin_time: Duration) -> Self

Sets the maximum cumulative amount of time for which listener creation may spin in retry loops.

Spinning under contention is, of course, avoided whenever possible, but certain features simply can’t be implemented without retry loops that have to loop for up to however long contention persists. If you’d like to limit the duration for which listener creation can be delayed by other processes, including potentially untrusted ones, set this option to a value that you consider reasonably low.

§Platform-specific behavior
§Unix

Made use of in the implementation of try_overwrite.

§Windows

Currently not used for anything.

Source§

impl ListenerOptions<'_>

Listener constructors.

Source

pub fn create_sync(self) -> Result<Listener>

Creates a Listener, binding it to the specified local socket name.

On platforms where there are multiple available implementations, this dispatches to the appropriate implementation based on where the name points to.

Source

pub fn create_sync_as<L: Listener>(self) -> Result<L>

Creates the given type of listener, binding it to the specified local socket name.

Source

pub fn create_tokio(self) -> Result<TokioListener>

Available on crate feature tokio only.

Creates a Tokio Listener, binding it to the specified local socket name.

On platforms where there are multiple available implementations, this dispatches to the appropriate implementation based on where the name points to.

Source

pub fn create_tokio_as<L: Listener>(self) -> Result<L>

Available on crate feature tokio only.

Creates the given type of listener, binding it to the specified local socket name.

Trait Implementations§

Source§

impl Debug for ListenerOptions<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ListenerOptions<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ListenerOptionsExt for ListenerOptions<'_>

Available on Unix only.
Source§

fn mode(self, mode: mode_t) -> Self

Sets the file mode (Unix permissions) to be applied to the socket file. This will authenticate clients using their process credentials according to the write bits of the mode; the read and execute bits are ignored by the OS and serve a cosmetic purpose. Read more
Source§

impl TryClone for ListenerOptions<'_>

Source§

fn try_clone(&self) -> Result<Self>

Clones self, possibly returning an error.

Auto Trait Implementations§

§

impl<'n> Freeze for ListenerOptions<'n>

§

impl<'n> RefUnwindSafe for ListenerOptions<'n>

§

impl<'n> Send for ListenerOptions<'n>

§

impl<'n> Sync for ListenerOptions<'n>

§

impl<'n> Unpin for ListenerOptions<'n>

§

impl<'n> UnsafeUnpin for ListenerOptions<'n>

§

impl<'n> UnwindSafe for ListenerOptions<'n>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.