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_unix_listener(&mut self, idx: usize) -> Result<Option<UnixListener>>

Takes the UNIX stream 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 UnixListener. If the fd at that position is not a UNIX stream socket then an error is returned and the fd is left at its place.

This function is only available on unix platforms.

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_unix_datagram(&mut self, idx: usize) -> Result<Option<UnixDatagram>>

Takes the UNIX datagram 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 UnixDatagram. If the fd at that position is not a UNIX datagram socket then an error is returned and the fd is left at its place.

This function is only available on unix platforms.

source

pub fn take_custom<T: FromRawFd>( &mut self, idx: usize, sock_fam: c_int, sock_type: c_int, hint: &str ) -> Result<Option<T>>

Takes a custom socket on unix platforms.

You have to provide a socket family, socket type, and a hint for the validation error, e.g. libc::AF_UNIX, libc::SOCK_SEQPACKET, "unix seqpacket socket".

The file descriptor will be validated to actually be a socket with the appropriate options, set as CLOEXEC, and converted to the given Rust type using FromRawFd.

This function is only available on unix platforms.

source

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

Takes the RawFd on unix platforms.

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.