Struct listenfd::ListenFd

source ·
pub struct ListenFd { /* private fields */ }
Expand description

A helper object that gives access to raw file descriptors.

Implementations§

source§

impl ListenFd

source

pub fn from_env() -> ListenFd

Creates the listenfd manager object from the environment.

source

pub fn empty() -> ListenFd

Creates an empty listenfd object.

This is helpful when the ability to work with external file descriptors should be disabled in certain code paths. This way the functions on the object will just never return sockets.

source

pub fn len(&self) -> usize

Returns the number of fds in the manager object.

Note that even if fds are taken out of the manager this count does not change.

source

pub fn take_tcp_listener(&mut self, idx: usize) -> Result<Option<TcpListener>>

Takes the TCP listener at an index.

If the given index has been used before Ok(None) is returned, otherwise the fd at that index is returned as TcpListener. If the fd at that position is not a TCP socket then an error is returned and the fd is left at its place.

source

pub fn take_udp_socket(&mut self, idx: usize) -> Result<Option<UdpSocket>>

Takes the UDP socket at an index.

If the given index has been used before Ok(None) is returned, otherwise the fd at that index is returned as UdpSocket. If the fd at that position is not a UDP socket then an error is returned and the fd is left at its place.

source

pub fn take_raw_socket(&mut self, idx: usize) -> Result<Option<RawSocket>>

Takes the RawSocket on windows platforms.

This will error if the fd at this position is not a socket (but a handle).

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.