pub struct ListenFd { /* private fields */ }
Expand description
A helper object that gives access to raw file descriptors.
Implementations§
source§impl ListenFd
impl ListenFd
sourcepub fn empty() -> ListenFd
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.
sourcepub fn len(&self) -> usize
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.
sourcepub fn take_tcp_listener(&mut self, idx: usize) -> Result<Option<TcpListener>>
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.
sourcepub fn take_unix_listener(&mut self, idx: usize) -> Result<Option<UnixListener>>
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.
sourcepub fn take_udp_socket(&mut self, idx: usize) -> Result<Option<UdpSocket>>
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.
sourcepub fn take_unix_datagram(&mut self, idx: usize) -> Result<Option<UnixDatagram>>
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.
sourcepub fn take_custom<T: FromRawFd>(
&mut self,
idx: usize,
sock_fam: c_int,
sock_type: c_int,
hint: &str
) -> Result<Option<T>>
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.