From 0abc612aaf9adffa7121af184296f718c0dcd4f1 Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Mon, 14 Apr 2025 11:05:38 +0100 Subject: [PATCH 1/4] add cygwin support --- src/poll.rs | 12 ++++++++---- src/sys/unix/mod.rs | 3 +++ src/sys/unix/net.rs | 1 + src/sys/unix/pipe.rs | 1 + src/sys/unix/tcp.rs | 1 + tests/tcp.rs | 5 +++-- tests/tcp_stream.rs | 8 +++++--- tests/udp_socket.rs | 8 +++++--- tests/unix_datagram.rs | 9 +++++++++ tests/unix_listener.rs | 2 ++ tests/unix_pipe.rs | 6 +++--- tests/unix_stream.rs | 12 ++++++++++++ 12 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/poll.rs b/src/poll.rs index f21266183..b4a83baa9 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -10,7 +10,8 @@ target_os = "hurd", target_os = "nto", target_os = "solaris", - target_os = "vita" + target_os = "vita", + target_os = "cygwin", )), ))] use std::os::fd::{AsRawFd, RawFd}; @@ -449,7 +450,8 @@ impl Poll { target_os = "hurd", target_os = "nto", target_os = "solaris", - target_os = "vita" + target_os = "vita", + target_os = "cygwin", )), ))] impl AsRawFd for Poll { @@ -750,7 +752,8 @@ impl fmt::Debug for Registry { target_os = "hurd", target_os = "nto", target_os = "solaris", - target_os = "vita" + target_os = "vita", + target_os = "cygwin", )), ))] impl AsRawFd for Registry { @@ -770,7 +773,8 @@ cfg_os_poll! { target_os = "hurd", target_os = "nto", target_os = "solaris", - target_os = "vita" + target_os = "vita", + target_os = "cygwin", )), ))] #[test] diff --git a/src/sys/unix/mod.rs b/src/sys/unix/mod.rs index 6c0c8850e..52ab8e58f 100644 --- a/src/sys/unix/mod.rs +++ b/src/sys/unix/mod.rs @@ -49,6 +49,7 @@ cfg_os_poll! { target_os = "nto", target_os = "solaris", target_os = "vita", + target_os = "cygwin", ), path = "selector/poll.rs")] mod selector; pub(crate) use self::selector::*; @@ -101,6 +102,7 @@ cfg_os_poll! { target_os = "redox", target_os = "solaris", target_os = "vita", + target_os = "cygwin", ), path = "waker/pipe.rs")] mod waker; // NOTE: the `Waker` type is expected in the selector module as the @@ -148,6 +150,7 @@ cfg_os_poll! { target_os = "redox", target_os = "solaris", target_os = "vita", + target_os = "cygwin", ), // Hermit doesn't support pipes. not(target_os = "hermit"), diff --git a/src/sys/unix/net.rs b/src/sys/unix/net.rs index 76451e9a2..e5ed95524 100644 --- a/src/sys/unix/net.rs +++ b/src/sys/unix/net.rs @@ -24,6 +24,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R target_os = "openbsd", target_os = "solaris", target_os = "hermit", + target_os = "cygwin", ))] let socket_type = socket_type | libc::SOCK_NONBLOCK | libc::SOCK_CLOEXEC; #[cfg(target_os = "nto")] diff --git a/src/sys/unix/pipe.rs b/src/sys/unix/pipe.rs index 0a3be9af2..7006576cb 100644 --- a/src/sys/unix/pipe.rs +++ b/src/sys/unix/pipe.rs @@ -21,6 +21,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> { target_os = "redox", target_os = "solaris", target_os = "vita", + target_os = "cygwin", ))] unsafe { if libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC | libc::O_NONBLOCK) != 0 { diff --git a/src/sys/unix/tcp.rs b/src/sys/unix/tcp.rs index 1d1965d9c..4dbdb73c5 100644 --- a/src/sys/unix/tcp.rs +++ b/src/sys/unix/tcp.rs @@ -75,6 +75,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, target_os = "netbsd", target_os = "openbsd", target_os = "solaris", + target_os = "cygwin", ))] let stream = { syscall!(accept4( diff --git a/tests/tcp.rs b/tests/tcp.rs index ca70938dc..62df5ee36 100644 --- a/tests/tcp.rs +++ b/tests/tcp.rs @@ -563,7 +563,7 @@ fn connect_error() { // Without fastopen we would be getting the connection error assert!(event.is_writable() || event.is_error()); // Solaris poll(2) says POLLHUP and POLLOUT are mutually exclusive. - #[cfg(not(target_os = "solaris"))] + #[cfg(not(any(target_os = "solaris", target_os = "cygwin")))] assert!(event.is_write_closed()); break 'outer; } @@ -695,7 +695,8 @@ fn write_shutdown() { if cfg!(any( target_os = "hurd", target_os = "solaris", - target_os = "nto" + target_os = "nto", + target_os = "cygwin", )) { wait!(poll, is_readable, false); } else { diff --git a/tests/tcp_stream.rs b/tests/tcp_stream.rs index 9ff3c39f2..6fe907041 100644 --- a/tests/tcp_stream.rs +++ b/tests/tcp_stream.rs @@ -550,7 +550,7 @@ fn tcp_shutdown_client_read_close_event() { } #[test] -#[cfg_attr(windows, ignore = "fails; client write_closed events are not found")] +#[cfg_attr(any(windows, target_os = "cygwin"), ignore = "fails; client write_closed events are not found")] #[cfg_attr( any( target_os = "android", @@ -596,6 +596,7 @@ fn tcp_shutdown_client_write_close_event() { #[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")] #[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")] #[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")] +#[cfg_attr(target_os = "cygwin", ignore = "POLLRDHUP isn't supported on Cygwin")] fn tcp_shutdown_server_write_close_event() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -629,6 +630,7 @@ fn tcp_shutdown_server_write_close_event() { #[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")] #[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")] #[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")] +#[cfg_attr(target_os = "cygwin", ignore = "POLLRDHUP isn't supported on Cygwin")] fn tcp_reset_close_event() { let (mut poll, mut events) = init_with_poll(); @@ -673,7 +675,7 @@ fn tcp_reset_close_event() { #[test] #[cfg_attr( - windows, + any(windows, target_os = "cygwin"), ignore = "fails on Windows; client close events are not found" )] #[cfg_attr( @@ -729,7 +731,7 @@ fn echo_listener(addr: SocketAddr, n_connections: usize) -> (thread::JoinHandle< // error when the reading side of the peer connection is // shutdown, we don't consider it an actual here. .or_else(|err| match err { - ref err if err.kind() == io::ErrorKind::ConnectionReset => Ok(0), + ref err if matches!(err.kind(), io::ErrorKind::ConnectionReset | io::ErrorKind::ConnectionAborted) => Ok(0), err => Err(err), }) .expect("error reading"); diff --git a/tests/udp_socket.rs b/tests/udp_socket.rs index 026329213..7883f6351 100644 --- a/tests/udp_socket.rs +++ b/tests/udp_socket.rs @@ -561,7 +561,7 @@ fn unconnected_udp_socket_connected_methods() { ); // Socket is unconnected, but we're using an connected method. - if cfg!(not(any(target_os = "hurd", target_os = "windows"))) { + if cfg!(not(any(target_os = "hurd", target_os = "windows", target_os = "cygwin"))) { assert_error(socket1.send(DATA1), "address required"); } if cfg!(target_os = "windows") { @@ -630,7 +630,8 @@ fn connected_udp_socket_unconnected_methods() { target_os = "android", target_os = "hurd", target_os = "linux", - target_os = "windows" + target_os = "windows", + target_os = "cygwin", )))] assert_error(socket1.send_to(DATA1, address2), "already connected"); // Even if the address is the same. @@ -638,7 +639,8 @@ fn connected_udp_socket_unconnected_methods() { target_os = "android", target_os = "hurd", target_os = "linux", - target_os = "windows" + target_os = "windows", + target_os = "cygwin", )))] assert_error(socket1.send_to(DATA1, address3), "already connected"); diff --git a/tests/unix_datagram.rs b/tests/unix_datagram.rs index 31da16c01..f94ea7624 100644 --- a/tests/unix_datagram.rs +++ b/tests/unix_datagram.rs @@ -31,6 +31,10 @@ fn is_send_and_sync() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr( + target_os = "cygwin", + ignore = "getting pathname isn't supported on Cygwin" +)] fn unix_datagram_smoke_unconnected() { init(); let path1 = temp_file("unix_datagram_smoke_unconnected1"); @@ -60,6 +64,10 @@ fn unix_datagram_smoke_connected() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr( + target_os = "cygwin", + ignore = "getting pathname isn't supported on Cygwin" +)] fn unix_datagram_smoke_unconnected_from_std() { init(); let path1 = temp_file("unix_datagram_smoke_unconnected_from_std1"); @@ -181,6 +189,7 @@ fn unix_datagram_pair() { #[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")] #[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")] #[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")] +#[cfg_attr(target_os = "cygwin", ignore = "POLLRDHUP isn't supported on Cygwin")] fn unix_datagram_shutdown() { let (mut poll, mut events) = init_with_poll(); let path1 = temp_file("unix_datagram_shutdown1"); diff --git a/tests/unix_listener.rs b/tests/unix_listener.rs index ce62d4fb6..e04d3298e 100644 --- a/tests/unix_listener.rs +++ b/tests/unix_listener.rs @@ -89,6 +89,7 @@ fn unix_listener_register() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_listener_reregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -116,6 +117,7 @@ fn unix_listener_reregister() { } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_listener_deregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); diff --git a/tests/unix_pipe.rs b/tests/unix_pipe.rs index 73c28419a..eea87325b 100644 --- a/tests/unix_pipe.rs +++ b/tests/unix_pipe.rs @@ -54,7 +54,7 @@ fn smoke() { #[test] #[cfg_attr( - any(target_os = "hurd", target_os = "nto"), + any(target_os = "hurd", target_os = "nto", target_os = "cygwin"), ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets" )] fn event_when_sender_is_dropped() { @@ -96,7 +96,7 @@ fn event_when_sender_is_dropped() { #[test] #[cfg_attr( - any(target_os = "hurd", target_os = "nto"), + any(target_os = "hurd", target_os = "nto", target_os = "cygwin"), ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets" )] fn event_when_receiver_is_dropped() { @@ -133,7 +133,7 @@ fn event_when_receiver_is_dropped() { #[test] #[cfg_attr( - any(target_os = "hurd", target_os = "nto"), + any(target_os = "hurd", target_os = "nto", target_os = "cygwin"), ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets" )] fn from_child_process_io() { diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index fda86bbc5..697080137 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -37,12 +37,14 @@ fn unix_stream_send_and_sync() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_smoke() { #[allow(clippy::redundant_closure)] smoke_test(|path| UnixStream::connect(path), "unix_stream_smoke"); } #[test] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_connect() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -86,6 +88,7 @@ fn unix_stream_connect() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_connect_addr() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -132,6 +135,7 @@ fn unix_stream_connect_addr() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_from_std() { smoke_test( |path| { @@ -183,6 +187,7 @@ fn unix_stream_pair() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_peer_addr() { init(); let (handle, expected_addr) = new_echo_listener(1, "unix_stream_peer_addr"); @@ -205,6 +210,7 @@ fn unix_stream_peer_addr() { #[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")] #[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")] #[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")] +#[cfg_attr(target_os = "cygwin", ignore = "POLLRDHUP isn't supported on Cygwin")] fn unix_stream_shutdown_read() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_read"); @@ -266,6 +272,7 @@ fn unix_stream_shutdown_read() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_shutdown_write() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_write"); @@ -328,6 +335,7 @@ fn unix_stream_shutdown_write() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_shutdown_both() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_both"); @@ -396,6 +404,7 @@ fn unix_stream_shutdown_both() { #[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")] #[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")] #[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")] +#[cfg_attr(target_os = "cygwin", ignore = "POLLRDHUP isn't supported on Cygwin")] fn unix_stream_shutdown_listener_write() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -433,6 +442,7 @@ fn unix_stream_shutdown_listener_write() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_register() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_register"); @@ -454,6 +464,7 @@ fn unix_stream_register() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_reregister() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_reregister"); @@ -482,6 +493,7 @@ fn unix_stream_reregister() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] +#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_deregister() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_deregister"); From bef3f3534fddc5f1760bbf929dff733a34b3b53a Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Mon, 14 Apr 2025 11:09:02 +0100 Subject: [PATCH 2/4] fix format --- tests/tcp_stream.rs | 14 ++++++++++++-- tests/udp_socket.rs | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/tcp_stream.rs b/tests/tcp_stream.rs index 6fe907041..433de7d12 100644 --- a/tests/tcp_stream.rs +++ b/tests/tcp_stream.rs @@ -550,7 +550,10 @@ fn tcp_shutdown_client_read_close_event() { } #[test] -#[cfg_attr(any(windows, target_os = "cygwin"), ignore = "fails; client write_closed events are not found")] +#[cfg_attr( + any(windows, target_os = "cygwin"), + ignore = "fails; client write_closed events are not found" +)] #[cfg_attr( any( target_os = "android", @@ -731,7 +734,14 @@ fn echo_listener(addr: SocketAddr, n_connections: usize) -> (thread::JoinHandle< // error when the reading side of the peer connection is // shutdown, we don't consider it an actual here. .or_else(|err| match err { - ref err if matches!(err.kind(), io::ErrorKind::ConnectionReset | io::ErrorKind::ConnectionAborted) => Ok(0), + ref err + if matches!( + err.kind(), + io::ErrorKind::ConnectionReset | io::ErrorKind::ConnectionAborted + ) => + { + Ok(0) + } err => Err(err), }) .expect("error reading"); diff --git a/tests/udp_socket.rs b/tests/udp_socket.rs index 7883f6351..20776b7d3 100644 --- a/tests/udp_socket.rs +++ b/tests/udp_socket.rs @@ -561,7 +561,11 @@ fn unconnected_udp_socket_connected_methods() { ); // Socket is unconnected, but we're using an connected method. - if cfg!(not(any(target_os = "hurd", target_os = "windows", target_os = "cygwin"))) { + if cfg!(not(any( + target_os = "hurd", + target_os = "windows", + target_os = "cygwin" + ))) { assert_error(socket1.send(DATA1), "address required"); } if cfg!(target_os = "windows") { From 31c23c81562bdedbb8c35544d365831f553cd1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 14 Apr 2025 21:47:44 +0800 Subject: [PATCH 3/4] add ignore reasons --- tests/unix_listener.rs | 4 ++-- tests/unix_stream.rs | 23 +++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/unix_listener.rs b/tests/unix_listener.rs index e04d3298e..2aa08fa42 100644 --- a/tests/unix_listener.rs +++ b/tests/unix_listener.rs @@ -89,7 +89,7 @@ fn unix_listener_register() { } #[test] -#[cfg_attr(target_os = "cygwin", ignore)] +#[cfg_attr(target_os = "cygwin", ignore = "Cygwin blocks on connect")] fn unix_listener_reregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -117,7 +117,7 @@ fn unix_listener_reregister() { } #[test] -#[cfg_attr(target_os = "cygwin", ignore)] +#[cfg_attr(target_os = "cygwin", ignore = "Cygwin blocks on connect")] fn unix_listener_deregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index 697080137..201c2c52f 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -37,14 +37,12 @@ fn unix_stream_send_and_sync() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_smoke() { #[allow(clippy::redundant_closure)] smoke_test(|path| UnixStream::connect(path), "unix_stream_smoke"); } #[test] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_connect() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -88,7 +86,6 @@ fn unix_stream_connect() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_connect_addr() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -135,7 +132,6 @@ fn unix_stream_connect_addr() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_from_std() { smoke_test( |path| { @@ -187,7 +183,7 @@ fn unix_stream_pair() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] +#[cfg_attr(target_os = "cygwin", ignore = "nonblocking connect doesn't handshake")] fn unix_stream_peer_addr() { init(); let (handle, expected_addr) = new_echo_listener(1, "unix_stream_peer_addr"); @@ -272,7 +268,6 @@ fn unix_stream_shutdown_read() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_shutdown_write() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_write"); @@ -335,7 +330,6 @@ fn unix_stream_shutdown_write() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_shutdown_both() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_shutdown_both"); @@ -364,7 +358,7 @@ fn unix_stream_shutdown_both() { stream.shutdown(Shutdown::Both).unwrap(); // Solaris never returns POLLHUP for sockets. - #[cfg(not(target_os = "solaris"))] + #[cfg(not(any(target_os = "solaris", target_os = "cygwin")))] expect_events( &mut poll, &mut events, @@ -442,7 +436,6 @@ fn unix_stream_shutdown_listener_write() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_register() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_register"); @@ -464,7 +457,6 @@ fn unix_stream_register() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] fn unix_stream_reregister() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_reregister"); @@ -493,7 +485,7 @@ fn unix_stream_reregister() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore)] +#[cfg_attr(target_os = "cygwin", ignore = "nonblocking connect doesn't handshake")] fn unix_stream_deregister() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_deregister"); @@ -605,7 +597,14 @@ fn new_echo_listener( amount } Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => continue, - Err(ref err) if err.kind() == io::ErrorKind::ConnectionReset => break, + Err(ref err) + if matches!( + err.kind(), + io::ErrorKind::ConnectionReset | io::ErrorKind::ConnectionAborted + ) => + { + break + } Err(err) => panic!("{}", err), }; if n == 0 { From 21ad9a53f894e8d86e5fad8d47f4910f072ade67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Thu, 5 Jun 2025 23:07:40 +0800 Subject: [PATCH 4/4] Enable ignored UDS tests --- tests/unix_listener.rs | 8 ++++++-- tests/unix_stream.rs | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/tests/unix_listener.rs b/tests/unix_listener.rs index 2aa08fa42..f73f86410 100644 --- a/tests/unix_listener.rs +++ b/tests/unix_listener.rs @@ -89,7 +89,6 @@ fn unix_listener_register() { } #[test] -#[cfg_attr(target_os = "cygwin", ignore = "Cygwin blocks on connect")] fn unix_listener_reregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -111,13 +110,15 @@ fn unix_listener_reregister() { &mut events, vec![ExpectEvent::new(TOKEN_1, Interest::READABLE)], ); + // Complete handshake to unblock the client thread. + #[cfg(target_os = "cygwin")] + listener.accept().unwrap(); barrier.wait(); handle.join().unwrap(); } #[test] -#[cfg_attr(target_os = "cygwin", ignore = "Cygwin blocks on connect")] fn unix_listener_deregister() { let (mut poll, mut events) = init_with_poll(); let barrier = Arc::new(Barrier::new(2)); @@ -132,6 +133,9 @@ fn unix_listener_deregister() { poll.registry().deregister(&mut listener).unwrap(); expect_no_events(&mut poll, &mut events); + // Complete handshake to unblock the client thread. + #[cfg(target_os = "cygwin")] + listener.accept().unwrap(); barrier.wait(); handle.join().unwrap(); diff --git a/tests/unix_stream.rs b/tests/unix_stream.rs index 201c2c52f..8a12a90aa 100644 --- a/tests/unix_stream.rs +++ b/tests/unix_stream.rs @@ -183,13 +183,31 @@ fn unix_stream_pair() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore = "nonblocking connect doesn't handshake")] fn unix_stream_peer_addr() { init(); let (handle, expected_addr) = new_echo_listener(1, "unix_stream_peer_addr"); let expected_path = expected_addr.as_pathname().expect("failed to get pathname"); let stream = UnixStream::connect(expected_path).unwrap(); + // Complete handshake to unblock the server thread. + #[cfg(target_os = "cygwin")] + let stream = { + let mut stream = stream; + let (mut poll, mut events) = init_with_poll(); + poll.registry() + .register( + &mut stream, + TOKEN_1, + Interest::READABLE.add(Interest::WRITABLE), + ) + .unwrap(); + expect_events( + &mut poll, + &mut events, + vec![ExpectEvent::new(TOKEN_1, Interest::WRITABLE)], + ); + stream + }; assert_eq!( stream.peer_addr().unwrap().as_pathname().unwrap(), @@ -485,13 +503,30 @@ fn unix_stream_reregister() { target_os = "hurd", ignore = "getting pathname isn't supported on GNU/Hurd" )] -#[cfg_attr(target_os = "cygwin", ignore = "nonblocking connect doesn't handshake")] fn unix_stream_deregister() { let (mut poll, mut events) = init_with_poll(); let (handle, remote_addr) = new_echo_listener(1, "unix_stream_deregister"); let path = remote_addr.as_pathname().expect("failed to get pathname"); let mut stream = UnixStream::connect(path).unwrap(); + // Complete handshake to unblock the server thread. + #[cfg(target_os = "cygwin")] + { + let (mut poll, mut events) = init_with_poll(); + poll.registry() + .register( + &mut stream, + TOKEN_1, + Interest::READABLE.add(Interest::WRITABLE), + ) + .unwrap(); + expect_events( + &mut poll, + &mut events, + vec![ExpectEvent::new(TOKEN_1, Interest::WRITABLE)], + ); + poll.registry().deregister(&mut stream).unwrap(); + } poll.registry() .register(&mut stream, TOKEN_1, Interest::WRITABLE) .unwrap();