Skip to content

Commit 56a9a8d

Browse files
committed
Add socket extensions for cygwin
1 parent c6c1796 commit 56a9a8d

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

library/std/src/os/net/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
all(target_vendor = "fortanix", target_env = "sgx")
1010
)
1111
)))]
12-
#[cfg(any(target_os = "linux", target_os = "android", doc))]
12+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
1313
pub(super) mod linux_ext;

library/std/src/os/unix/net/addr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ impl SocketAddr {
255255
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
256256
impl Sealed for SocketAddr {}
257257

258-
#[doc(cfg(any(target_os = "android", target_os = "linux")))]
259-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
258+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
259+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
260260
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
261261
impl linux_ext::addr::SocketAddrExt for SocketAddr {
262262
fn as_abstract_name(&self) -> Option<&[u8]> {

library/std/src/os/unix/net/tests.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn long_path() {
170170
#[test]
171171
#[cfg(not(target_os = "nto"))]
172172
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
173+
#[cfg_attr(target_os = "cygwin", ignore)] // Cygwin ignores timeout
173174
fn timeouts() {
174175
let dir = tmpdir();
175176
let socket_path = dir.path().join("sock");
@@ -198,6 +199,7 @@ fn timeouts() {
198199

199200
#[test]
200201
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
202+
#[cfg_attr(target_os = "cygwin", ignore)] // Cygwin ignores timeout
201203
fn test_read_timeout() {
202204
let dir = tmpdir();
203205
let socket_path = dir.path().join("sock");
@@ -218,6 +220,7 @@ fn test_read_timeout() {
218220

219221
#[test]
220222
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
223+
#[cfg_attr(target_os = "cygwin", ignore)] // Cygwin ignores timeout
221224
fn test_read_with_timeout() {
222225
let dir = tmpdir();
223226
let socket_path = dir.path().join("sock");
@@ -246,6 +249,7 @@ fn test_read_with_timeout() {
246249
// when passed zero Durations
247250
#[test]
248251
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
252+
#[cfg_attr(target_os = "cygwin", ignore)] // Cygwin ignores timeout
249253
fn test_unix_stream_timeout_zero_duration() {
250254
let dir = tmpdir();
251255
let socket_path = dir.path().join("sock");
@@ -416,7 +420,7 @@ fn abstract_namespace_not_allowed_connect() {
416420
assert!(UnixStream::connect("\0asdf").is_err());
417421
}
418422

419-
#[cfg(any(target_os = "android", target_os = "linux"))]
423+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
420424
#[test]
421425
fn test_abstract_stream_connect() {
422426
let msg1 = b"hello";
@@ -447,7 +451,7 @@ fn test_abstract_stream_connect() {
447451
thread.join().unwrap();
448452
}
449453

450-
#[cfg(any(target_os = "android", target_os = "linux"))]
454+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
451455
#[test]
452456
fn test_abstract_stream_iter() {
453457
let addr = or_panic!(SocketAddr::from_abstract_name(b"hidden"));
@@ -469,7 +473,7 @@ fn test_abstract_stream_iter() {
469473
thread.join().unwrap();
470474
}
471475

472-
#[cfg(any(target_os = "android", target_os = "linux"))]
476+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
473477
#[test]
474478
fn test_abstract_datagram_bind_send_to_addr() {
475479
let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns1"));
@@ -490,7 +494,7 @@ fn test_abstract_datagram_bind_send_to_addr() {
490494
assert_eq!(addr.as_abstract_name().unwrap(), b"ns1");
491495
}
492496

493-
#[cfg(any(target_os = "android", target_os = "linux"))]
497+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
494498
#[test]
495499
fn test_abstract_datagram_connect_addr() {
496500
let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns3"));
@@ -515,7 +519,7 @@ fn test_abstract_datagram_connect_addr() {
515519
or_panic!(bsock2.recv_from(&mut buf));
516520
}
517521

518-
#[cfg(any(target_os = "android", target_os = "linux"))]
522+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
519523
#[test]
520524
fn test_abstract_name_too_long() {
521525
match SocketAddr::from_abstract_name(
@@ -529,7 +533,7 @@ fn test_abstract_name_too_long() {
529533
}
530534
}
531535

532-
#[cfg(any(target_os = "android", target_os = "linux"))]
536+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
533537
#[test]
534538
fn test_abstract_no_pathname_and_not_unnamed() {
535539
let name = b"local";
@@ -660,7 +664,7 @@ fn test_send_vectored_fds_unix_stream() {
660664
}
661665
}
662666

663-
#[cfg(any(target_os = "android", target_os = "linux"))]
667+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
664668
#[test]
665669
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
666670
fn test_send_vectored_with_ancillary_to_unix_datagram() {

library/std/src/sys/net/connection/socket/unix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,12 @@ impl Socket {
459459
Ok(raw != 0)
460460
}
461461

462-
#[cfg(any(target_os = "android", target_os = "linux",))]
462+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
463463
pub fn set_quickack(&self, quickack: bool) -> io::Result<()> {
464464
setsockopt(self, libc::IPPROTO_TCP, libc::TCP_QUICKACK, quickack as c_int)
465465
}
466466

467-
#[cfg(any(target_os = "android", target_os = "linux",))]
467+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
468468
pub fn quickack(&self) -> io::Result<bool> {
469469
let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_QUICKACK)?;
470470
Ok(raw != 0)
@@ -513,12 +513,12 @@ impl Socket {
513513
Ok(name)
514514
}
515515

516-
#[cfg(any(target_os = "android", target_os = "linux",))]
516+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
517517
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
518518
setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int)
519519
}
520520

521-
#[cfg(any(target_os = "android", target_os = "linux",))]
521+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
522522
pub fn passcred(&self) -> io::Result<bool> {
523523
let passcred: libc::c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED)?;
524524
Ok(passcred != 0)

0 commit comments

Comments
 (0)