Skip to content

Commit a4cc392

Browse files
committed
Add docs for set_no_peercred
1 parent 0d1639c commit a4cc392

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/socket.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ impl Socket {
200200
/// non-blocking mode before calling this function), socket option can't be
201201
/// set *while connecting*. This will cause errors on Windows. Socket
202202
/// options can be safely set before and after connecting the socket.
203+
///
204+
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
205+
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`].
203206
pub fn connect(&self, address: &SockAddr) -> io::Result<()> {
204207
sys::connect(self.as_raw(), address)
205208
}
@@ -260,6 +263,11 @@ impl Socket {
260263
/// This function sets the same flags as in done for [`Socket::new`],
261264
/// [`Socket::accept_raw`] can be used if you don't want to set those flags.
262265
#[doc = man_links!(accept(2))]
266+
///
267+
/// # Notes
268+
///
269+
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
270+
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`].
263271
pub fn accept(&self) -> io::Result<(Socket, SockAddr)> {
264272
// Use `accept4` on platforms that support it.
265273
#[cfg(any(

src/sys/unix.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,15 @@ impl crate::Socket {
15021502
}
15031503

15041504
/// Sets `SO_PEERCRED` to null on the socket.
1505-
/// It disables the initial handshake of unix domain sockets.
1505+
/// This is a Cygwin extension.
1506+
///
1507+
/// Normally the Unix domain sockets of Cygwin are implemented by TCP sockets,
1508+
/// so it performs a handshake on `connect` and `accept`, to verify the remote
1509+
/// connection and exchange peer cred info. Therefore, `connect` blocks until
1510+
/// the server `accept`s it. This option turns off the handshake. Both client
1511+
/// and server should turn it off to let `connect` returns immediately.
1512+
///
1513+
/// See also: the [mailing list](https://inbox.sourceware.org/cygwin/TYCPR01MB10926FF8926CA63704867ADC8F8AA2@TYCPR01MB10926.jpnprd01.prod.outlook.com/)
15061514
#[cfg(target_os = "cygwin")]
15071515
pub fn set_no_peercred(&self) -> io::Result<()> {
15081516
syscall!(setsockopt(

0 commit comments

Comments
 (0)