Skip to content
Merged
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
- sparcv9-sun-solaris
- x86_64-apple-darwin
- x86_64-apple-ios
- x86_64-pc-cygwin
- x86_64-pc-solaris
# Fails with:
# `rror calling dlltool 'x86_64-w64-mingw32-dlltool': No such file or
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl TcpKeepalive {
target_os = "tvos",
target_os = "watchos",
target_os = "windows",
target_os = "cygwin",
))]
pub const fn with_interval(self, interval: Duration) -> Self {
Self {
Expand Down Expand Up @@ -543,6 +544,7 @@ impl TcpKeepalive {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub const fn with_retries(self, retries: u32) -> Self {
Expand Down
28 changes: 26 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ impl Socket {
/// non-blocking mode before calling this function), socket option can't be
/// set *while connecting*. This will cause errors on Windows. Socket
/// options can be safely set before and after connecting the socket.
///
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`]
/// (Cygwin only).
#[allow(rustdoc::broken_intra_doc_links)] // Socket::set_no_peercred
pub fn connect(&self, address: &SockAddr) -> io::Result<()> {
sys::connect(self.as_raw(), address)
}
Expand Down Expand Up @@ -260,6 +265,13 @@ impl Socket {
/// This function sets the same flags as in done for [`Socket::new`],
/// [`Socket::accept_raw`] can be used if you don't want to set those flags.
#[doc = man_links!(accept(2))]
///
/// # Notes
///
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`]
/// (Cygwin only).
#[allow(rustdoc::broken_intra_doc_links)] // Socket::set_no_peercred
pub fn accept(&self) -> io::Result<(Socket, SockAddr)> {
// Use `accept4` on platforms that support it.
#[cfg(any(
Expand All @@ -271,6 +283,7 @@ impl Socket {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
return self._accept4(libc::SOCK_CLOEXEC);

Expand All @@ -284,6 +297,7 @@ impl Socket {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))]
{
let (socket, addr) = self.accept_raw()?;
Expand Down Expand Up @@ -752,6 +766,7 @@ const fn set_common_type(ty: Type) -> Type {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
let ty = ty._cloexec();

Expand Down Expand Up @@ -781,6 +796,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
target_os = "openbsd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
socket._set_cloexec(true)?;
Expand Down Expand Up @@ -956,7 +972,7 @@ impl Socket {
/// For more information about this option, see [`set_passcred`].
///
/// [`set_passcred`]: Socket::set_passcred
#[cfg(all(unix, target_os = "linux"))]
#[cfg(any(target_os = "linux", target_os = "cygwin"))]
pub fn passcred(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::SOL_SOCKET, sys::SO_PASSCRED)
Expand All @@ -968,7 +984,7 @@ impl Socket {
///
/// If this option is enabled, enables the receiving of the `SCM_CREDENTIALS`
/// control messages.
#[cfg(all(unix, target_os = "linux"))]
#[cfg(any(target_os = "linux", target_os = "cygwin"))]
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
unsafe {
setsockopt(
Expand Down Expand Up @@ -1254,6 +1270,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn join_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1287,6 +1304,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn leave_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1577,6 +1595,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn set_recv_tos_v4(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1608,6 +1627,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn recv_tos_v4(&self) -> io::Result<bool> {
unsafe {
Expand Down Expand Up @@ -1978,6 +1998,7 @@ impl Socket {
target_os = "hurd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
pub fn recv_hoplimit_v6(&self) -> io::Result<bool> {
Expand Down Expand Up @@ -2006,6 +2027,7 @@ impl Socket {
target_os = "hurd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
pub fn set_recv_hoplimit_v6(&self, recv_hoplimit: bool) -> io::Result<()> {
Expand Down Expand Up @@ -2063,6 +2085,7 @@ impl Socket {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub fn keepalive_interval(&self) -> io::Result<Duration> {
Expand Down Expand Up @@ -2092,6 +2115,7 @@ impl Socket {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub fn keepalive_retries(&self) -> io::Result<u32> {
Expand Down
Loading