Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ impl Type {
pub const DCCP: Type = Type(sys::SOCK_DCCP);

/// Type corresponding to `SOCK_SEQPACKET`.
#[cfg(all(feature = "all", not(any(target_os = "espidf", target_os = "wasi"))))]
#[cfg(all(feature = "all", not(any(target_os = "espidf", target_os = "wasi", target_os = "horizon"))))]
pub const SEQPACKET: Type = Type(sys::SOCK_SEQPACKET);

/// Type corresponding to `SOCK_RAW`.
#[cfg(all(
feature = "all",
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi"))
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi", target_os = "horizon"))
))]
pub const RAW: Type = Type(sys::SOCK_RAW);
}
Expand Down Expand Up @@ -371,11 +371,11 @@ impl From<Protocol> for c_int {
/// Flags for incoming messages.
///
/// Flags provide additional information about incoming messages.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
#[derive(Copy, Clone, Eq, PartialEq)]
pub struct RecvFlags(c_int);

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
impl RecvFlags {
/// Check if the message contains a truncated datagram.
///
Expand All @@ -384,7 +384,7 @@ impl RecvFlags {
///
/// On Unix this corresponds to the `MSG_TRUNC` flag.
/// On Windows this corresponds to the `WSAEMSGSIZE` error code.
#[cfg(not(target_os = "espidf"))]
#[cfg(not(any(target_os = "espidf")))]
Comment thread
Thomasdezeeuw marked this conversation as resolved.
Outdated
pub const fn is_truncated(self) -> bool {
self.0 & sys::MSG_TRUNC != 0
}
Expand Down Expand Up @@ -573,15 +573,15 @@ impl TcpKeepalive {
///
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdrMut`]
/// for the variant used by `recvmsg(2)`.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
#[repr(transparent)]
pub struct MsgHdr<'addr, 'bufs, 'control> {
inner: sys::msghdr,
#[allow(clippy::type_complexity)]
_lifetimes: PhantomData<(&'addr SockAddr, &'bufs IoSlice<'bufs>, &'control [u8])>,
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
/// Create a new `MsgHdr` with all empty/zero fields.
#[allow(clippy::new_without_default)]
Expand Down Expand Up @@ -631,21 +631,21 @@ impl<'addr, 'bufs, 'control> MsgHdr<'addr, 'bufs, 'control> {
}
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
impl<'name, 'bufs, 'control> fmt::Debug for MsgHdr<'name, 'bufs, 'control> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"MsgHdr".fmt(fmt)
}
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
unsafe impl Send for MsgHdr<'_, '_, '_> {}

/// Configuration of a `recvmsg(2)` system call.
///
/// This wraps `msghdr` on Unix and `WSAMSG` on Windows. Also see [`MsgHdr`] for
/// the variant used by `sendmsg(2)`.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
#[repr(transparent)]
pub struct MsgHdrMut<'addr, 'bufs, 'control> {
inner: sys::msghdr,
Expand All @@ -657,7 +657,7 @@ pub struct MsgHdrMut<'addr, 'bufs, 'control> {
)>,
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
/// Create a new `MsgHdrMut` with all empty/zero fields.
#[allow(clippy::new_without_default)]
Expand Down Expand Up @@ -712,12 +712,12 @@ impl<'addr, 'bufs, 'control> MsgHdrMut<'addr, 'bufs, 'control> {
}
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
impl<'name, 'bufs, 'control> fmt::Debug for MsgHdrMut<'name, 'bufs, 'control> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
"MsgHdrMut".fmt(fmt)
}
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
unsafe impl Send for MsgHdrMut<'_, '_, '_> {}
48 changes: 30 additions & 18 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use std::os::windows::io::{FromRawSocket, IntoRawSocket};
use std::time::Duration;

use crate::sys::{self, c_int, getsockopt, setsockopt, Bool};
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(all(unix, not(any(target_os = "horizon", target_os = "redox"))))]
Comment thread
Thomasdezeeuw marked this conversation as resolved.
Outdated
use crate::MsgHdrMut;
use crate::{Domain, Protocol, SockAddr, TcpKeepalive, Type};
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
use crate::{MaybeUninitSlice, MsgHdr, RecvFlags};

/// Owned wrapper around a system socket.
Expand Down Expand Up @@ -470,7 +470,7 @@ impl Socket {
/// Note that the [`io::Read::read_vectored`] implementation calls this
/// function with `buf`s of type `&mut [IoSliceMut]`, allowing initialised
/// buffers to be used without using `unsafe`.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn recv_vectored(
&self,
bufs: &mut [MaybeUninitSlice<'_>],
Expand All @@ -489,7 +489,7 @@ impl Socket {
/// as [`recv_vectored`].
///
/// [`recv_vectored`]: Socket::recv_vectored
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn recv_vectored_with_flags(
&self,
bufs: &mut [MaybeUninitSlice<'_>],
Expand Down Expand Up @@ -554,7 +554,7 @@ impl Socket {
/// as [`recv_vectored`].
///
/// [`recv_vectored`]: Socket::recv_vectored
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn recv_from_vectored(
&self,
bufs: &mut [MaybeUninitSlice<'_>],
Expand All @@ -573,7 +573,7 @@ impl Socket {
/// as [`recv_vectored`].
///
/// [`recv_vectored`]: Socket::recv_vectored
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn recv_from_vectored_with_flags(
&self,
bufs: &mut [MaybeUninitSlice<'_>],
Expand Down Expand Up @@ -632,7 +632,7 @@ impl Socket {
/// <https://github.com/microsoft/Windows-classic-samples/blob/7cbd99ac1d2b4a0beffbaba29ea63d024ceff700/Samples/Win7Samples/netds/winsock/recvmsg/rmmc.cpp>
/// for an example (in C++).
#[doc = man_links!(recvmsg(2))]
#[cfg(all(unix, not(target_os = "redox")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
Comment thread
Thomasdezeeuw marked this conversation as resolved.
Outdated
pub fn recvmsg(&self, msg: &mut MsgHdrMut<'_, '_, '_>, flags: sys::c_int) -> io::Result<usize> {
sys::recvmsg(self.as_raw(), msg, flags)
}
Expand All @@ -657,7 +657,7 @@ impl Socket {
}

/// Send data to the connected peer. Returns the amount of bytes written.
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn send_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.send_vectored_with_flags(bufs, 0)
}
Expand All @@ -667,7 +667,7 @@ impl Socket {
#[doc = man_links!(sendmsg(2))]
///
/// [`send_vectored`]: Socket::send_vectored
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn send_vectored_with_flags(
&self,
bufs: &[IoSlice<'_>],
Expand Down Expand Up @@ -714,7 +714,7 @@ impl Socket {
/// Send data to a peer listening on `addr`. Returns the amount of bytes
/// written.
#[doc = man_links!(sendmsg(2))]
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn send_to_vectored(&self, bufs: &[IoSlice<'_>], addr: &SockAddr) -> io::Result<usize> {
self.send_to_vectored_with_flags(bufs, addr, 0)
}
Expand All @@ -723,7 +723,7 @@ impl Socket {
/// arbitrary flags to the underlying `sendmsg`/`WSASendTo` call.
///
/// [`send_to_vectored`]: Socket::send_to_vectored
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn send_to_vectored_with_flags(
&self,
bufs: &[IoSlice<'_>],
Expand All @@ -735,7 +735,7 @@ impl Socket {

/// Send a message on a socket using a message structure.
#[doc = man_links!(sendmsg(2))]
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
pub fn sendmsg(&self, msg: &MsgHdr<'_, '_, '_>, flags: sys::c_int) -> io::Result<usize> {
sys::sendmsg(self.as_raw(), msg, flags)
}
Expand Down Expand Up @@ -1211,7 +1211,7 @@ impl Socket {
/// [`set_header_included_v4`]: Socket::set_header_included_v4
#[cfg(all(
feature = "all",
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi"))
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi", target_os = "horizon"))
))]
pub fn header_included_v4(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -1237,7 +1237,7 @@ impl Socket {
)]
#[cfg(all(
feature = "all",
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi"))
not(any(target_os = "redox", target_os = "espidf", target_os = "wasi", target_os = "horizon"))
))]
pub fn set_header_included_v4(&self, included: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1344,6 +1344,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn join_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1379,6 +1380,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn leave_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1415,6 +1417,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn join_ssm_v4(
&self,
Expand Down Expand Up @@ -1454,6 +1457,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn leave_ssm_v4(
&self,
Expand Down Expand Up @@ -1677,6 +1681,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn set_recv_tos_v4(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1710,6 +1715,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn recv_tos_v4(&self) -> io::Result<bool> {
unsafe {
Expand Down Expand Up @@ -1754,6 +1760,7 @@ impl Socket {
target_os = "dragonfly",
target_os = "netbsd",
target_os = "wasi",
target_os = "horizon"
))
))]
pub fn header_included_v6(&self) -> io::Result<bool> {
Expand Down Expand Up @@ -1785,6 +1792,7 @@ impl Socket {
target_os = "dragonfly",
target_os = "netbsd",
target_os = "wasi",
target_os = "horizon"
))
))]
pub fn set_header_included_v6(&self, included: bool) -> io::Result<()> {
Expand Down Expand Up @@ -2084,6 +2092,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn recv_tclass_v6(&self) -> io::Result<bool> {
unsafe {
Expand All @@ -2110,6 +2119,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
target_os = "wasi",
target_os = "horizon"
)))]
pub fn set_recv_tclass_v6(&self, recv_tclass: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -2144,6 +2154,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
))
))]
pub fn recv_hoplimit_v6(&self) -> io::Result<bool> {
Expand Down Expand Up @@ -2174,6 +2185,7 @@ impl Socket {
target_os = "vita",
target_os = "cygwin",
target_os = "wasi",
target_os = "horizon"
))
))]
pub fn set_recv_hoplimit_v6(&self, recv_hoplimit: bool) -> io::Result<()> {
Expand Down Expand Up @@ -2373,7 +2385,7 @@ impl Read for Socket {
self.recv(buf)
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
// Safety: both `IoSliceMut` and `MaybeUninitSlice` promise to have the
// same layout, that of `iovec`/`WSABUF`. Furthermore, `recv_vectored`
Expand All @@ -2391,7 +2403,7 @@ impl<'a> Read for &'a Socket {
self.recv(buf)
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
// Safety: see other `Read::read` impl.
let bufs = unsafe { &mut *(bufs as *mut [IoSliceMut<'_>] as *mut [MaybeUninitSlice<'_>]) };
Expand All @@ -2404,7 +2416,7 @@ impl Write for Socket {
self.send(buf)
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.send_vectored(bufs)
}
Expand All @@ -2419,7 +2431,7 @@ impl<'a> Write for &'a Socket {
self.send(buf)
}

#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
#[cfg(not(any(target_os = "redox", target_os = "wasi", target_os = "horizon")))]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
self.send_vectored(bufs)
}
Expand Down
Loading
Loading