Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: eagerly implement common traits #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ancillary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub fn send_ancillary(
/// An ancillary data buffer that supports any capacity.
///
/// For reasonable ancillary capacities it uses a stack-based array.
#[derive(Clone)]
#[repr(C)]
pub struct AncillaryBuf {
capacity: ControlLen,
Expand Down Expand Up @@ -288,6 +289,7 @@ impl AsMut<[u8]> for AncillaryBuf {
}
}

#[derive(Copy, Clone)]
pub struct FdSliceIterator<'a> {
pos: usize,
slice: &'a FdSlice<'a>,
Expand All @@ -309,6 +311,7 @@ impl<'a> Iterator for FdSliceIterator<'a> {
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct FdSlice<'a> {
/// The underlying buffer as ptr
unaligned_ptr: *const RawFd,
Expand Down Expand Up @@ -372,6 +375,7 @@ pub enum AncillaryItem<'a> {
}

/// An iterator over ancillary messages received with `recv_ancillary()`.
#[derive(Clone)]
pub struct Ancillary<'a> {
// addr and bytes are not used here:
// * addr is usually placed on the stack by the calling wrapper method,
Expand Down
2 changes: 1 addition & 1 deletion src/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub type RawReceivedCredentials = libc::ucred;
/// * On FreeBSD, NetBSD, DragonFly BSD, Illumos and likely macOS it is provided
/// by the OS automatically when the socket option is set.
/// * OpenBSD doesn't appear to support receiving credentials.
#[derive(Clone,Copy, PartialEq,Eq,Hash, Debug)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct ReceivedCredentials {
#[cfg(any(target_os="linux", target_os="android", target_os="dragonfly"))]
pid: u32,
Expand Down
5 changes: 4 additions & 1 deletion src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn set_nonblocking(fd: RawFd, nonblocking: bool) -> Result<(), io::Error> {
}



#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct SetAddr(unsafe extern "C" fn(RawFd, *const sockaddr, socklen_t) -> c_int);
impl SetAddr {
pub const LOCAL: Self = SetAddr(bind);
Expand All @@ -100,6 +100,7 @@ pub fn set_unix_addr(socket: RawFd, set_side: SetAddr, addr: &UnixSocketAddr)
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct GetAddr(unsafe extern "C" fn(RawFd, *mut sockaddr, *mut socklen_t) -> c_int);
impl GetAddr {
pub const LOCAL: Self = GetAddr(getsockname);
Expand Down Expand Up @@ -140,6 +141,7 @@ pub fn take_error(socket: RawFd) -> Result<Option<io::Error>, io::Error> {
}
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[repr(C)]
pub struct TimeoutDirection(c_int);
impl TimeoutDirection {
Expand Down Expand Up @@ -211,6 +213,7 @@ pub fn get_timeout(socket: RawFd, direction: TimeoutDirection)

/// Used in setup of sockets to ensure the file descriptor is always closed
/// if later parts of the setup fails.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
pub struct Socket(RawFd);

impl Drop for Socket {
Expand Down
8 changes: 4 additions & 4 deletions src/seqpacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ macro_rules! impl_mio_if_enabled {($type:tt) => {
/// .expect("connect to abstract seqpacket listener");
/// let (_server, _addr) = listener.accept_unix_addr().unwrap();
/// ```
#[derive(Debug)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[repr(transparent)]
pub struct UnixSeqpacketConn {
fd: RawFd,
Expand Down Expand Up @@ -535,7 +535,7 @@ impl UnixSeqpacketConn {
/// conn.send(b"Welcome").unwrap();
/// # std::fs::remove_file("seqpacket_listener.socket").unwrap();
/// ```
#[derive(Debug)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[repr(transparent)]
pub struct UnixSeqpacketListener {
fd: RawFd
Expand Down Expand Up @@ -743,7 +743,7 @@ impl UnixSeqpacketListener {
/// assert_eq!(current_events[0].token(), Token(1));
/// assert_eq!(a.recv(&mut [0; 8]).expect("receive packet"), 8/*truncated*/);
/// ```
#[derive(Debug)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[repr(transparent)]
pub struct NonblockingUnixSeqpacketConn {
fd: RawFd,
Expand Down Expand Up @@ -1020,7 +1020,7 @@ impl NonblockingUnixSeqpacketConn {
/// let (_, _addr) = listener.accept_unix_addr().expect("accept connection");
/// # let _ = std::fs::remove_file("seqpacket.sock"); // clean up after ourself on success
/// ```
#[derive(Debug)]
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[repr(transparent)]
pub struct NonblockingUnixSeqpacketListener {
fd: RawFd
Expand Down
2 changes: 2 additions & 0 deletions src/tokio/seqpacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio_crate::io::Interest;
use tokio_crate::io::unix::AsyncFd;

/// An I/O object representing a Unix Sequenced-packet socket.
#[derive(Debug)]
pub struct UnixSeqpacketConn {
io: AsyncFd<nonblocking::UnixSeqpacketConn>,
}
Expand Down Expand Up @@ -179,6 +180,7 @@ impl IntoRawFd for UnixSeqpacketConn {


/// An I/O object representing a Unix Sequenced-packet socket.
#[derive(Debug)]
pub struct UnixSeqpacketListener {
io: AsyncFd<nonblocking::UnixSeqpacketListener>,
}
Expand Down