Skip to content

Commit 8148306

Browse files
committed
Move set_no_peercred
1 parent d84efb3 commit 8148306

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/socket.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,30 @@ impl Socket {
992992
}
993993
}
994994

995+
/// Sets `SO_PEERCRED` to null on the socket.
996+
///
997+
/// This is a Cygwin extension.
998+
///
999+
/// Normally the Unix domain sockets of Cygwin are implemented by TCP sockets,
1000+
/// so it performs a handshake on `connect` and `accept` to verify the remote
1001+
/// connection and exchange peer cred info. At the time of writing, this
1002+
/// means that `connect` on a Unix domain socket will block until the server
1003+
/// calls `accept` on Cygwin. This behavior is inconsistent with most other
1004+
/// platforms, and this option can be used to disable that.
1005+
///
1006+
/// See also: the [mailing list](https://inbox.sourceware.org/cygwin/TYCPR01MB10926FF8926CA63704867ADC8F8AA2@TYCPR01MB10926.jpnprd01.prod.outlook.com/)
1007+
#[cfg(any(doc, target_os = "cygwin"))]
1008+
pub fn set_no_peercred(&self) -> io::Result<()> {
1009+
#[cfg(target_os = "cygwin")]
1010+
{
1011+
self._set_no_peercred()
1012+
}
1013+
#[cfg(not(target_os = "cygwin"))]
1014+
{
1015+
unimplemented!()
1016+
}
1017+
}
1018+
9951019
/// Get value for the `SO_RCVBUF` option on this socket.
9961020
///
9971021
/// For more information about this option, see [`set_recv_buffer_size`].

src/sys/unix.rs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,35 +1501,16 @@ impl crate::Socket {
15011501
}
15021502
}
15031503

1504-
/// Sets `SO_PEERCRED` to null on the socket.
1505-
///
1506-
/// This is a Cygwin extension.
1507-
///
1508-
/// Normally the Unix domain sockets of Cygwin are implemented by TCP sockets,
1509-
/// so it performs a handshake on `connect` and `accept` to verify the remote
1510-
/// connection and exchange peer cred info. At the time of writing, this
1511-
/// means that `connect` on a Unix domain socket will block until the server
1512-
/// calls `accept` on Cygwin. This behavior is inconsistent with most other
1513-
/// platforms, and this option can be used to disable that.
1514-
///
1515-
/// See also: the [mailing list](https://inbox.sourceware.org/cygwin/TYCPR01MB10926FF8926CA63704867ADC8F8AA2@TYCPR01MB10926.jpnprd01.prod.outlook.com/)
1516-
#[cfg(any(doc, all(feature = "all", target_os = "cygwin")))]
1517-
pub fn set_no_peercred(&self) -> io::Result<()> {
1518-
#[cfg(target_os = "cygwin")]
1519-
{
1520-
syscall!(setsockopt(
1521-
self.as_raw(),
1522-
SOL_SOCKET,
1523-
SO_PEERCRED,
1524-
ptr::null_mut(),
1525-
0,
1526-
))
1527-
.map(|_| ())
1528-
}
1529-
#[cfg(not(target_os = "cygwin"))]
1530-
{
1531-
unimplemented!()
1532-
}
1504+
#[cfg(target_os = "cygwin")]
1505+
pub(crate) fn _set_no_peercred(&self) -> io::Result<()> {
1506+
syscall!(setsockopt(
1507+
self.as_raw(),
1508+
SOL_SOCKET,
1509+
SO_PEERCRED,
1510+
ptr::null_mut(),
1511+
0,
1512+
))
1513+
.map(|_| ())
15331514
}
15341515

15351516
/// Sets `SO_NOSIGPIPE` on the socket.

0 commit comments

Comments
 (0)