#[cfg(any(
target_vendor="apple", target_os="freebsd",
target_os="netbsd",
target_os="illumos", target_os="solaris",
))]
use std::io::ErrorKind;
use std::
{
io::{self, IoSlice, IoSliceMut}, net::Shutdown, ops::{Deref, DerefMut}, os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd}, path::Path, time::Duration
};
use libc::{MSG_EOR, MSG_PEEK, c_void, send, recv};
use crate::{UnixSocketAddr, helpers::*};
use crate::ancillary::*;
use crate::credentials::*;
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[cfg_attr(any(target_os="linux", target_os="android"), doc="```")]
#[cfg_attr(not(any(target_os="linux", target_os="android")), doc="```no_run")]
#[derive(Debug)]
#[repr(transparent)]
pub struct UnixSeqpacketConn
{
fd: OwnedFd,
}
impl From<OwnedFd> for UnixSeqpacketConn
{
fn from(ofd: OwnedFd) -> Self
{
let sa_fam = get_socket_family(&ofd).unwrap();
let sa_type = get_socket_type(&ofd).unwrap() & 0x00000FFF;
if sa_fam as i32 != libc::AF_UNIX || sa_type != libc::SOCK_SEQPACKET
{
panic!("assertion trap: provided FD is not AF_UNIX & SOCK_SEQPACKET, {} {}",
sa_fam, sa_type);
}
return UnixSeqpacketConn{ fd: ofd };
}
}
impl From<UnixSeqpacketConn> for OwnedFd
{
fn from(value: UnixSeqpacketConn) -> Self
{
return value.fd;
}
}
impl FromRawFd for UnixSeqpacketConn
{
unsafe
fn from_raw_fd(fd: RawFd) -> Self
{
UnixSeqpacketConn::from( unsafe { OwnedFd::from_raw_fd(fd) } )
}
}
impl AsRawFd for UnixSeqpacketConn
{
fn as_raw_fd(&self) -> RawFd
{
self.fd.as_raw_fd()
}
}
impl IntoRawFd for UnixSeqpacketConn
{
fn into_raw_fd(self) -> RawFd
{
self.fd.into_raw_fd()
}
}
impl AsFd for UnixSeqpacketConn
{
fn as_fd(&self) -> BorrowedFd<'_>
{
self.fd.as_fd()
}
}
#[cfg(feature = "mio")]
pub mod mio_conn_enabled
{
use mio::{event::Source, unix::SourceFd};
use super::*;
impl Source for UnixSeqpacketConn
{
fn register(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.set_nonblocking(true)?;
SourceFd(&self.fd.as_raw_fd()).register(registry, token, interests)
}
fn reregister(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
SourceFd(&self.fd.as_raw_fd()).reregister(registry, token, interests)
}
fn deregister(&mut self, registry: &mio::Registry) -> io::Result<()>
{
SourceFd(&self.fd.as_raw_fd()).deregister(registry)
}
}
}
#[cfg(feature = "xio-rs")]
pub mod xio_conn_enabled
{
use xio_rs::{EsInterfaceRegistry, XioChannel, XioEventPipe, XioEventUid, XioResult, event_registry::XioRegistry};
use crate::UnixSeqpacketConn;
impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR, Self> for UnixSeqpacketConn
{
fn connect_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.set_nonblocking(true)?;
ess.get_ev_sys().en_register(&self.fd, ev_uid, channel)
}
fn modify_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
ess.get_ev_sys().re_register(&self.fd, ev_uid, channel)
}
fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
{
ess.get_ev_sys().de_register(&self.fd)
}
}
}
impl UnixSeqpacketConn
{
pub
fn connect<P: AsRef<Path>>(path: P) -> Result<Self, io::Error>
{
let addr = UnixSocketAddr::from_path(&path)?;
return Self::connect_unix_addr(&addr);
}
pub
fn connect_unix_addr(addr: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(false)?;
socket.set_unix_peer_addr(addr)?;
return Ok(UnixSeqpacketConn { fd: socket.into() });
}
pub
fn connect_from_to_unix_addr(from: &UnixSocketAddr, to: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(false)?;
socket.set_unix_local_addr(from)?;
socket.set_unix_peer_addr(to)?;
return Ok(UnixSeqpacketConn{ fd: socket.into() });
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn pair() -> Result<(Self, Self), io::Error>
{
let pair = Socket::<SocketSeqPkt>::pair(false)?;
return Ok(
(
UnixSeqpacketConn { fd: pair.0.into() },
UnixSeqpacketConn { fd: pair.1.into() }
)
);
}
pub
fn local_unix_addr(&self) -> Result<UnixSocketAddr, io::Error>
{
get_unix_local_addr(&self)
}
pub
fn peer_unix_addr(&self) -> Result<UnixSocketAddr, io::Error>
{
get_unix_peer_addr(&self)
}
pub
fn initial_peer_credentials(&self) -> Result<ConnCredentials, io::Error>
{
peer_credentials(&self)
}
pub
fn initial_peer_selinux_context(&self, buf: &mut[u8]) -> Result<usize, io::Error>
{
selinux_context(&self, buf)
}
pub
fn send(&self, packet: &[u8]) -> Result<usize, io::Error>
{
let ptr = packet.as_ptr() as *const c_void;
let flags = MSG_NOSIGNAL | MSG_EOR;
let sent = cvt_r!(unsafe { send(self.fd.as_raw_fd(), ptr, packet.len(), flags) })?;
return Ok(sent as usize);
}
pub
fn send_flags(&self, packet: &[u8], flags: i32) -> Result<usize, io::Error>
{
let ptr = packet.as_ptr() as *const c_void;
let sent = cvt_r!(unsafe { send(self.fd.as_raw_fd(), ptr, packet.len(), flags) })?;
return Ok(sent as usize);
}
pub
fn recv(&self, buffer: &mut[u8]) -> Result<usize, io::Error>
{
let ptr = buffer.as_ptr() as *mut c_void;
let received = cvt_r!(unsafe { recv(self.fd.as_raw_fd(), ptr, buffer.len(), MSG_NOSIGNAL) })?;
return Ok(received as usize);
}
pub
fn send_vectored(&self, slices: &[IoSlice]) -> Result<usize, io::Error>
{
send_ancillary(&self, None, MSG_EOR, slices, Vec::new(), None)
}
pub
fn recv_vectored(&self, buffers: &mut[IoSliceMut]) -> Result<(usize, bool), io::Error>
{
recv_ancillary(&self, None, 0, buffers, &mut[])
.map(|(bytes, ancillary)| (bytes, ancillary.message_truncated()) )
}
pub
fn send_fds(&self, bytes: &[u8], fds: Vec<OwnedFd>) -> Result<usize, io::Error>
{
send_ancillary(&self, None, MSG_EOR, &[IoSlice::new(bytes)], fds, None)
}
pub
fn recv_fds(&self, byte_buffer: &mut[u8], fd_buffer: &mut Vec<OwnedFd>) -> Result<(usize, bool, usize), io::Error>
{
recv_fds(&self, None, &mut[IoSliceMut::new(byte_buffer)], Some(fd_buffer))
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn peek(&self, buffer: &mut[u8]) -> Result<usize, io::Error>
{
let ptr = buffer.as_ptr() as *mut c_void;
let flags = MSG_NOSIGNAL | MSG_PEEK;
let received = cvt_r!(unsafe { recv(self.fd.as_raw_fd(), ptr, buffer.len(), flags) })?;
return Ok(received as usize);
}
pub
fn peek_vectored(&self, buffers: &mut[IoSliceMut]) -> Result<(usize, bool), io::Error>
{
recv_ancillary(&self, None, MSG_PEEK, buffers, &mut[])
.map(|(bytes, ancillary)| (bytes, ancillary.message_truncated()) )
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn take_error(&self) -> Result<Option<io::Error>, io::Error>
{
take_error(&self)
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn try_clone(&self) -> Result<Self, io::Error>
{
let cloned = Socket::<SocketSeqPkt>::try_clone_from(self)?;
return Ok(UnixSeqpacketConn { fd: cloned.into() });
}
#[cfg_attr(not(any(target_vendor="apple", target_os="illumos", target_os="solaris")), doc="```")]
#[cfg_attr(any(target_vendor="apple", target_os="illumos", target_os="solaris"), doc="```no_run")]
pub
fn set_read_timeout(&self, timeout: Option<Duration>) -> Result<(), io::Error>
{
set_timeout(self.fd.as_fd(), TimeoutDirection::Read, timeout)
}
#[cfg_attr(not(any(target_vendor="apple", target_os="illumos", target_os="solaris")), doc="```")]
#[cfg_attr(any(target_vendor="apple", target_os="illumos", target_os="solaris"), doc="```no_run")]
pub
fn read_timeout(&self) -> Result<Option<Duration>, io::Error>
{
get_timeout(self.fd.as_fd(), TimeoutDirection::Read)
}
#[cfg_attr(not(any(target_vendor="apple", target_os="illumos", target_os="solaris")), doc="```")]
#[cfg_attr(any(target_vendor="apple", target_os="illumos", target_os="solaris"), doc="```no_run")]
pub
fn set_write_timeout(&self, timeout: Option<Duration>)-> Result<(), io::Error>
{
set_timeout(self.fd.as_fd(), TimeoutDirection::Write, timeout)
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn write_timeout(&self) -> Result<Option<Duration>, io::Error>
{
get_timeout(self.fd.as_fd(), TimeoutDirection::Write)
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn set_nonblocking(&self, nonblocking: bool) -> Result<(), io::Error>
{
set_nonblocking(&self, nonblocking)
}
pub
fn shutdown(&self, how: Shutdown) -> io::Result<()>
{
let how =
match how
{
Shutdown::Read => libc::SHUT_RD,
Shutdown::Write => libc::SHUT_WR,
Shutdown::Both => libc::SHUT_RDWR,
};
unsafe { cvt!(libc::shutdown(self.as_raw_fd(), how)) }?;
return Ok(());
}
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[derive(Debug)]
#[repr(transparent)]
pub struct UnixSeqpacketListener
{
fd: OwnedFd
}
impl From<OwnedFd> for UnixSeqpacketListener
{
fn from(ofd: OwnedFd) -> Self
{
let sa_fam = get_socket_family(&ofd).unwrap();
let sa_type = get_socket_type(&ofd).unwrap() & 0x00000FFF;
if sa_fam as i32 != libc::AF_UNIX || sa_type != libc::SOCK_SEQPACKET
{
panic!("assertion trap: provided FD is not AF_UNIX & SOCK_SEQPACKET, {} {}",
sa_fam, sa_type);
}
return UnixSeqpacketListener{ fd: ofd };
}
}
impl From<UnixSeqpacketListener> for OwnedFd
{
fn from(value: UnixSeqpacketListener) -> Self
{
return value.fd;
}
}
impl FromRawFd for UnixSeqpacketListener
{
unsafe
fn from_raw_fd(fd: RawFd) -> Self
{
UnixSeqpacketListener::from( unsafe { OwnedFd::from_raw_fd(fd) } )
}
}
impl AsRawFd for UnixSeqpacketListener
{
fn as_raw_fd(&self) -> RawFd
{
self.fd.as_raw_fd()
}
}
impl IntoRawFd for UnixSeqpacketListener
{
fn into_raw_fd(self) -> RawFd
{
self.fd.into_raw_fd()
}
}
impl AsFd for UnixSeqpacketListener
{
fn as_fd(&self) -> BorrowedFd<'_>
{
self.fd.as_fd()
}
}
#[cfg(feature = "mio")]
pub mod mio_listener_enabled
{
use std::{io, os::fd::AsRawFd};
use mio::{event::Source, unix::SourceFd};
use crate::UnixSeqpacketListener;
impl Source for UnixSeqpacketListener
{
fn register(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.set_nonblocking(true)?;
SourceFd(&self.fd.as_raw_fd()).register(registry, token, interests)
}
fn reregister(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
SourceFd(&self.fd.as_raw_fd()).reregister(registry, token, interests)
}
fn deregister(&mut self, registry: &mio::Registry) -> io::Result<()>
{
SourceFd(&self.fd.as_raw_fd()).deregister(registry)
}
}
}
#[cfg(feature = "xio-rs")]
pub mod xio_listener_enabled
{
use xio_rs::{EsInterfaceRegistry, XioChannel, XioEventPipe, XioEventUid, XioResult, event_registry::XioRegistry};
use crate::UnixSeqpacketListener;
impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR, Self> for UnixSeqpacketListener
{
fn connect_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.set_nonblocking(true)?;
ess.get_ev_sys().en_register(&self.fd, ev_uid, channel)
}
fn modify_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
ess.get_ev_sys().re_register(&self.fd, ev_uid, channel)
}
fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
{
ess.get_ev_sys().de_register(&self.fd)
}
}
}
impl UnixSeqpacketListener
{
pub
fn bind<P: AsRef<Path>>(path: P) -> Result<Self, io::Error>
{
let addr = UnixSocketAddr::from_path(path.as_ref())?;
return Self::bind_unix_addr(&addr);
}
pub
fn bind_unix_addr(addr: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(false)?;
socket.set_unix_local_addr(addr)?;
socket.start_listening()?;
return Ok(UnixSeqpacketListener { fd: socket.into() });
}
pub
fn local_unix_addr(&self) -> Result<UnixSocketAddr, io::Error>
{
get_unix_local_addr(&self)
}
pub
fn accept_unix_addr(&self)-> Result<(UnixSeqpacketConn, UnixSocketAddr), io::Error>
{
let (socket, addr) = Socket::<SocketSeqPkt>::accept_from(&self, false)?;
let conn = UnixSeqpacketConn { fd: socket.into() };
return Ok((conn, addr));
}
pub
fn take_error(&self) -> Result<Option<io::Error>, io::Error>
{
take_error(&self)
}
pub
fn try_clone(&self) -> Result<Self, io::Error>
{
let cloned = Socket::<SocketSeqPkt>::try_clone_from(&self)?;
return Ok(UnixSeqpacketListener { fd: cloned.into() });
}
#[cfg_attr(any(target_os="linux", target_os="android"), doc="```")]
#[cfg_attr(not(any(target_os="linux", target_os="android")), doc="```no_run")]
pub
fn set_timeout(&self, timeout: Option<Duration>) -> Result<(), io::Error>
{
let res = set_timeout(&self, TimeoutDirection::Read, timeout);
#[cfg(any(
target_vendor="apple", target_os="freebsd",
target_os="netbsd",
target_os="illumos", target_os="solaris",
))]
{
if res.is_ok() == true && timeout.is_some() == true
{
return Err(
io::Error::new(
ErrorKind::InvalidInput,
"listener timeouts are not supported on this OS"
)
);
}
}
return res;
}
#[cfg_attr(any(target_os="linux", target_os="android"), doc="```")]
#[cfg_attr(not(any(target_os="linux", target_os="android")), doc="```no_run")]
pub
fn timeout(&self) -> Result<Option<Duration>, io::Error>
{
get_timeout(&self, TimeoutDirection::Read)
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn set_nonblocking(&self, nonblocking: bool) -> Result<(), io::Error>
{
set_nonblocking(&self, nonblocking)
}
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[derive(Debug)]
#[repr(transparent)]
pub struct NonblockingUnixSeqpacketConn
{
usc: UnixSeqpacketConn,
}
impl From<OwnedFd> for NonblockingUnixSeqpacketConn
{
fn from(value: OwnedFd) -> Self
{
let usc = UnixSeqpacketConn::from(value);
usc.set_nonblocking(true).unwrap();
return Self{ usc: usc };
}
}
impl From<NonblockingUnixSeqpacketConn> for OwnedFd
{
fn from(value: NonblockingUnixSeqpacketConn) -> Self
{
return value.usc.fd;
}
}
impl FromRawFd for NonblockingUnixSeqpacketConn
{
unsafe
fn from_raw_fd(fd: RawFd) -> Self
{
let usc = unsafe{ UnixSeqpacketConn::from_raw_fd(fd) };
usc.set_nonblocking(true).unwrap();
return Self{ usc: usc };
}
}
impl AsRawFd for NonblockingUnixSeqpacketConn
{
fn as_raw_fd(&self) -> RawFd
{
self.usc.as_raw_fd()
}
}
impl IntoRawFd for NonblockingUnixSeqpacketConn
{
fn into_raw_fd(self) -> RawFd
{
self.usc.into_raw_fd()
}
}
impl AsFd for NonblockingUnixSeqpacketConn
{
fn as_fd(&self) -> BorrowedFd<'_>
{
self.usc.as_fd()
}
}
impl Deref for NonblockingUnixSeqpacketConn
{
type Target = UnixSeqpacketConn;
fn deref(&self) -> &Self::Target
{
&self.usc
}
}
impl DerefMut for NonblockingUnixSeqpacketConn
{
fn deref_mut(&mut self) -> &mut Self::Target
{
&mut self.usc
}
}
#[cfg(feature = "mio")]
pub mod mio_non_blk_conn_enabled
{
use std::io;
use mio::event::Source;
use super::NonblockingUnixSeqpacketConn;
impl Source for NonblockingUnixSeqpacketConn
{
fn register(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.usc.register(registry, token, interests)
}
fn reregister(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.usc.reregister(registry, token, interests)
}
fn deregister(&mut self, registry: &mio::Registry) -> io::Result<()>
{
self.usc.deregister(registry)
}
}
}
#[cfg(feature = "xio-rs")]
pub mod xio_non_blk_conn_enabled
{
use xio_rs::{EsInterfaceRegistry, XioChannel, XioEventPipe, XioEventUid, XioResult, event_registry::XioRegistry};
use super::NonblockingUnixSeqpacketConn;
impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR, Self> for NonblockingUnixSeqpacketConn
{
fn connect_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.usc.connect_event_pipe(ess, ev_uid, channel)
}
fn modify_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.usc.modify_event_pipe(ess, ev_uid, channel)
}
fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
{
self.usc.disconnect_event_pipe(ess)
}
}
}
impl NonblockingUnixSeqpacketConn
{
pub
fn connect<P: AsRef<Path>>(path: P) -> Result<Self, io::Error>
{
let addr = UnixSocketAddr::from_path(&path)?;
return Self::connect_unix_addr(&addr);
}
pub
fn connect_unix_addr(addr: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(true)?;
socket.set_unix_peer_addr(addr)?;
return Ok(
NonblockingUnixSeqpacketConn
{
usc: UnixSeqpacketConn { fd: socket.into() }
}
);
}
pub
fn connect_from_to_unix_addr(from: &UnixSocketAddr, to: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(true)?;
socket.set_unix_local_addr(from)?;
socket.set_unix_peer_addr(to)?;
return Ok(
NonblockingUnixSeqpacketConn
{
usc: UnixSeqpacketConn { fd: socket.into() }
}
);
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn pair() -> Result<(Self, Self), io::Error>
{
let pair = Socket::<SocketSeqPkt>::pair(true)?;
return Ok(
(
Self{ usc: UnixSeqpacketConn { fd: pair.0.into() } },
Self{ usc: UnixSeqpacketConn { fd: pair.1.into() } },
)
);
}
pub
fn try_clone(&self) -> Result<Self, io::Error>
{
let cloned = Socket::<SocketSeqPkt>::try_clone_from(self)?;
return Ok(
NonblockingUnixSeqpacketConn
{
usc: UnixSeqpacketConn { fd: cloned.into() }
}
);
}
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
#[derive(Debug)]
#[repr(transparent)]
pub struct NonblockingUnixSeqpacketListener
{
usl: UnixSeqpacketListener,
}
impl From<OwnedFd> for NonblockingUnixSeqpacketListener
{
fn from(ofd: OwnedFd) -> Self
{
let usl = UnixSeqpacketListener::from(ofd);
usl.set_nonblocking(true).unwrap();
return Self{ usl };
}
}
impl FromRawFd for NonblockingUnixSeqpacketListener
{
unsafe
fn from_raw_fd(fd: RawFd) -> Self
{
let usl = unsafe{ UnixSeqpacketListener::from_raw_fd(fd) };
usl.set_nonblocking(true).unwrap();
return Self{ usl };
}
}
impl From<NonblockingUnixSeqpacketListener> for OwnedFd
{
fn from(value: NonblockingUnixSeqpacketListener) -> Self
{
return value.usl.fd;
}
}
impl AsRawFd for NonblockingUnixSeqpacketListener
{
fn as_raw_fd(&self) -> RawFd
{
self.usl.as_raw_fd()
}
}
impl IntoRawFd for NonblockingUnixSeqpacketListener
{
fn into_raw_fd(self) -> RawFd
{
self.usl.into_raw_fd()
}
}
impl AsFd for NonblockingUnixSeqpacketListener
{
fn as_fd(&self) -> BorrowedFd<'_>
{
self.usl.as_fd()
}
}
impl Deref for NonblockingUnixSeqpacketListener
{
type Target = UnixSeqpacketListener;
fn deref(&self) -> &Self::Target
{
&self.usl
}
}
impl DerefMut for NonblockingUnixSeqpacketListener
{
fn deref_mut(&mut self) -> &mut Self::Target
{
&mut self.usl
}
}
impl NonblockingUnixSeqpacketListener
{
pub
fn bind<P: AsRef<Path>>(path: P) -> Result<Self, io::Error>
{
let addr = UnixSocketAddr::from_path(&path)?;
return Self::bind_unix_addr(&addr);
}
pub
fn bind_unix_addr(addr: &UnixSocketAddr) -> Result<Self, io::Error>
{
let socket = Socket::<SocketSeqPkt>::new(true)?;
socket.set_unix_local_addr(addr)?;
socket.start_listening()?;
return Ok( Self{ usl: UnixSeqpacketListener{ fd: socket.into() }} );
}
#[cfg_attr(not(target_vendor="apple"), doc="```")]
#[cfg_attr(target_vendor="apple", doc="```no_run")]
pub
fn accept_unix_addr(&self) -> Result<(NonblockingUnixSeqpacketConn, UnixSocketAddr), io::Error>
{
let (socket, addr) = Socket::<SocketSeqPkt>::accept_from(&self, true)?;
let conn = NonblockingUnixSeqpacketConn { usc: UnixSeqpacketConn{ fd: socket.into() }};
return Ok((conn, addr));
}
}
#[cfg(feature = "mio")]
pub mod mio_non_blk_listener_enabled
{
use std::{io, os::fd::AsRawFd};
use mio::{event::Source, unix::SourceFd};
use super::NonblockingUnixSeqpacketListener;
impl Source for NonblockingUnixSeqpacketListener
{
fn register(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.usl.register(registry, token, interests)
}
fn reregister(
&mut self,
registry: &mio::Registry,
token: mio::Token,
interests: mio::Interest,
) -> io::Result<()>
{
self.usl.reregister(registry, token, interests)
}
fn deregister(&mut self, registry: &mio::Registry) -> io::Result<()>
{
self.usl.deregister(registry)
}
}
}
#[cfg(feature = "xio-rs")]
pub mod xio_non_blk_listener_enabled
{
use xio_rs::{EsInterfaceRegistry, XioChannel, XioEventPipe, XioEventUid, XioResult, event_registry::XioRegistry};
use super::NonblockingUnixSeqpacketListener;
impl<ESSR: EsInterfaceRegistry> XioEventPipe<ESSR, Self> for NonblockingUnixSeqpacketListener
{
fn connect_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.usl.connect_event_pipe(ess, ev_uid, channel)
}
fn modify_event_pipe(&mut self, ess: &XioRegistry<ESSR>, ev_uid: XioEventUid, channel: XioChannel) -> XioResult<()>
{
self.usl.modify_event_pipe(ess, ev_uid, channel)
}
fn disconnect_event_pipe(&mut self, ess: &XioRegistry<ESSR>) -> XioResult<()>
{
self.usl.disconnect_event_pipe(ess)
}
}
}