pub struct UnixSeqpacketListener { /* private fields */ }Expand description
An unix domain listener for sequential packet connections.
See UnixSeqpacketConn for a description
of this type of connection.
§Registering with Xio (xio-rs) a feature = “xio-rs”
A XioEventPipe is implemented on this function. During initial registration
an attempt set nonblocking mode is performed during initial registration.
See examples below.
§Registering with Mio (mio) a feature = “mio”
A Source is implemented on the instance.During initial registration
an attempt set nonblocking mode is performed during initial registration.
§Examples
use tempfile::TempDir;
let dir = tempfile::tempdir().unwrap();
let mut file_path = dir.path().join("seqpacket_listener.socket");
let listener = uds_fork::UnixSeqpacketListener::bind(&file_path)
.expect("Create seqpacket listener");
let _client = uds_fork::UnixSeqpacketConn::connect(&file_path).unwrap();
let (conn, _addr) = listener.accept_unix_addr().unwrap();
conn.send(b"Welcome").unwrap();§Xio
let listener = uds_fork::UnixSeqpacketListener::bind(file_path).unwrap();
let mut reg = XioPollRegistry::<ESS>::new().unwrap();
let mut event_buf = XioPollRegistry::<ESS>::allocate_events(128.try_into().unwrap());
// either
let a_wrapped =
reg.get_registry()
.en_register_wrap(listener, XioEventUid::manual(1), XioChannel::INPUT)
.unwrap();
// or
reg.get_registry()
.en_register&mut listener, XioEventUid::manual(1), XioChannel::INPUT)
.unwrap();
// so depending on the method, use either:
a_wrapped.inner();
// or continue using a directly§Mio:
let listener = uds_fork::UnixSeqpacketListener::bind(file_path).unwrap();
let mut poll = Poll::new().expect("create mio poll");
let mut events = Events::with_capacity(10);
poll.registry()
.register(&mut listener, Token(1), Interest::READABLE)
.unwrap();
// ...Implementations§
Source§impl UnixSeqpacketListener
impl UnixSeqpacketListener
Sourcepub fn bind<P: AsRef<Path>>(path: P) -> Result<Self, Error>
pub fn bind<P: AsRef<Path>>(path: P) -> Result<Self, Error>
Creates a socket that listens for seqpacket connections on the specified socket file.
Sourcepub fn bind_unix_addr(addr: &UnixSocketAddr) -> Result<Self, Error>
pub fn bind_unix_addr(addr: &UnixSocketAddr) -> Result<Self, Error>
Creates a socket that listens for seqpacket connections on the specified address.
Sourcepub fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>
pub fn local_unix_addr(&self) -> Result<UnixSocketAddr, Error>
Returns the address the socket is listening on.
Sourcepub fn accept(&self) -> Result<(UnixSeqpacketConn, UnixSocketAddr), Error>
pub fn accept(&self) -> Result<(UnixSeqpacketConn, UnixSocketAddr), Error>
Accepts a new incoming connection to this listener.
Rustdocs:
This function will block the calling thread until a new Unix connection is established. When established, the corresponding
UnixSeqpacketConnand the remote peer’s address will be returned.
§Examples
use uds_fork::UnixSeqpacketListener;
fn main() -> std::io::Result<()>
{
let listener = UnixSeqpacketListener::bind("/path/to/the/socket")?;
match listener.accept()
{
Ok((socket, addr)) =>
println!("Got a client: {addr:?}"),
Err(e) =>
println!("accept function failed: {e:?}"),
}
return Ok(());
}Sourcepub fn accept_unix_addr(
&self,
) -> Result<(UnixSeqpacketConn, UnixSocketAddr), Error>
pub fn accept_unix_addr( &self, ) -> Result<(UnixSeqpacketConn, UnixSocketAddr), Error>
Accepts a new incoming connection to this listener.
See Self::accept.
Sourcepub fn take_error(&self) -> Result<Option<Error>, Error>
pub fn take_error(&self) -> Result<Option<Error>, Error>
Returns the value of the SO_ERROR option.
This might never produce any errors for listeners. It is therefore
unlikely to be useful, but is provided for parity with
std::unix::net::UnixListener.
Sourcepub fn try_clone(&self) -> Result<Self, Error>
pub fn try_clone(&self) -> Result<Self, Error>
Creates a new file descriptor listening for the same connections.
Sourcepub fn set_timeout(&self, timeout: Option<Duration>) -> Result<(), Error>
pub fn set_timeout(&self, timeout: Option<Duration>) -> Result<(), Error>
Sets a maximum duration to wait in a single accept() on this socket.
None disables a previously set timeout.
An error is returned if the duration is zero.
§Operating System Support
Only Linux appers to apply timeouts to accept().
On macOS, FreeBSD and NetBSD, timeouts are silently ignored.
On Illumos setting timeouts for all unix domain sockets silently fails.
On OSes where timeouts are known to not work, this function will return an error even if setting the timeout didn’t fail.
§Examples
let listener = UnixSeqpacketListener::bind_unix_addr(&addr).unwrap();
listener.set_timeout(Some(Duration::new(0, 200_000_000))).unwrap();
let err = listener.accept_unix_addr().unwrap_err();
assert_eq!(err.kind(), ErrorKind::WouldBlock);Sourcepub fn timeout(&self) -> Result<Option<Duration>, Error>
pub fn timeout(&self) -> Result<Option<Duration>, Error>
Returns the timeout for accept() on this socket.
None is returned if there is no timeout.
Even if a timeout has is set, it is ignored by accept() on
most operating systems except Linux.
§Examples
let listener = UnixSeqpacketListener::bind_unix_addr(&addr).unwrap();
assert_eq!(listener.timeout().unwrap(), None);
let timeout = Some(Duration::new(2, 0));
listener.set_timeout(timeout).unwrap();
assert_eq!(listener.timeout().unwrap(), timeout);Sourcepub fn set_nonblocking(&self, nonblocking: bool) -> Result<(), Error>
pub fn set_nonblocking(&self, nonblocking: bool) -> Result<(), Error>
Enables or disables nonblocking-ness of [accept_unix_addr()](#method.accept_unix addr).
The returned connnections will still be in blocking mode regardsless.
Consider using the nonblocking variant of this type instead;
this method mostly exists for feature parity with std’s UnixListener.
§Examples
use tempfile::TempDir;
let dir = tempfile::tempdir().unwrap();
let mut file_path = dir.path().join("nonblocking_seqpacket_listener1.socket");
let addr = UnixSocketAddr::from_path(&file_path).unwrap();
let listener = UnixSeqpacketListener::bind_unix_addr(&addr).expect("create listener");
listener.set_nonblocking(true).expect("enable noblocking mode");
assert_eq!(listener.accept_unix_addr().unwrap_err().kind(), ErrorKind::WouldBlock);Sourcepub fn incoming(&self) -> Incoming<'_>
pub fn incoming(&self) -> Incoming<'_>
Returns an iterator over incoming connections.
Rustdoc:
The iterator will never return
Noneand will also not yield the peer’sUnixSocketAddrstructure.
use std::thread;
use uds_fork::{UnixSeqpacketConn, UnixSeqpacketListener};
fn handle_client(stream: UnixSeqpacketConn)
{
// ...
}
fn main() -> std::io::Result<()>
{
let listener = UnixSeqpacketListener::bind("/path/to/the/socket")?;
for stream in listener.incoming()
{
match stream
{
Ok(stream) =>
{
thread::spawn(|| handle_client(stream));
},
Err(err) =>
{
break;
}
}
}
return Ok(());
}Trait Implementations§
Source§impl AsFd for UnixSeqpacketListener
impl AsFd for UnixSeqpacketListener
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl AsRawFd for UnixSeqpacketListener
impl AsRawFd for UnixSeqpacketListener
Source§impl Debug for UnixSeqpacketListener
impl Debug for UnixSeqpacketListener
Source§impl From<OwnedFd> for UnixSeqpacketListener
impl From<OwnedFd> for UnixSeqpacketListener
Source§impl From<UnixSeqpacketListener> for OwnedFd
impl From<UnixSeqpacketListener> for OwnedFd
Source§fn from(value: UnixSeqpacketListener) -> Self
fn from(value: UnixSeqpacketListener) -> Self
Source§impl FromRawFd for UnixSeqpacketListener
impl FromRawFd for UnixSeqpacketListener
Source§unsafe fn from_raw_fd(fd: RawFd) -> Self
unsafe fn from_raw_fd(fd: RawFd) -> Self
Self from the given raw file
descriptor. Read moreSource§impl<'a> IntoIterator for &'a UnixSeqpacketListener
impl<'a> IntoIterator for &'a UnixSeqpacketListener
Source§impl IntoRawFd for UnixSeqpacketListener
impl IntoRawFd for UnixSeqpacketListener
Source§fn into_raw_fd(self) -> RawFd
fn into_raw_fd(self) -> RawFd
Source§impl Source for UnixSeqpacketListener
impl Source for UnixSeqpacketListener
Source§impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR> for UnixSeqpacketListener
impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR> for UnixSeqpacketListener
Source§fn connect_event_pipe(
&mut self,
ess: &XioRegistry<ESSR>,
ev_uid: XioEventUid,
channel: XioChannel,
) -> XioResult<()>
fn connect_event_pipe( &mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel, ) -> XioResult<()>
self to the endpoint which is provided by the argument
ess.Source§fn modify_event_pipe(
&mut self,
ess: &XioRegistry<ESSR>,
ev_uid: XioEventUid,
channel: XioChannel,
) -> XioResult<()>
fn modify_event_pipe( &mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel, ) -> XioResult<()>
Source§fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
self from the ess provided endpoint. An instance which
implements the logic should check that the ess matches the ess used when
self was initially registered (if available).