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
48 changes: 46 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ 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`].
pub fn connect(&self, address: &SockAddr) -> io::Result<()> {
sys::connect(self.as_raw(), address)
}
Expand Down Expand Up @@ -260,6 +263,11 @@ 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`].
pub fn accept(&self) -> io::Result<(Socket, SockAddr)> {
// Use `accept4` on platforms that support it.
#[cfg(any(
Expand All @@ -271,6 +279,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 +293,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 +762,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 +792,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 +968,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 +980,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 All @@ -980,6 +992,30 @@ impl Socket {
}
}

/// Sets `SO_PEERCRED` to null on the socket.
///
/// This is a Cygwin extension.
///
/// Normally the Unix domain sockets of Cygwin are implemented by TCP sockets,
/// so it performs a handshake on `connect` and `accept` to verify the remote
/// connection and exchange peer cred info. At the time of writing, this
/// means that `connect` on a Unix domain socket will block until the server
/// calls `accept` on Cygwin. This behavior is inconsistent with most other
/// platforms, and this option can be used to disable that.
///
/// See also: the [mailing list](https://inbox.sourceware.org/cygwin/TYCPR01MB10926FF8926CA63704867ADC8F8AA2@TYCPR01MB10926.jpnprd01.prod.outlook.com/)
#[cfg(any(doc, target_os = "cygwin"))]
pub fn set_no_peercred(&self) -> io::Result<()> {
#[cfg(target_os = "cygwin")]
{
self._set_no_peercred()
}
#[cfg(not(target_os = "cygwin"))]
{
unimplemented!()
}
}

/// Get value for the `SO_RCVBUF` option on this socket.
///
/// For more information about this option, see [`set_recv_buffer_size`].
Expand Down Expand Up @@ -1254,6 +1290,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 +1324,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 +1615,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 +1647,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 +2018,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 +2047,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 +2105,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 +2135,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