Skip to content

Commit f73099c

Browse files
committed
Add socket extensions for cygwin
1 parent 5771665 commit f73099c

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
@@ -256,8 +256,8 @@ impl SocketAddr {
256256
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
257257
impl Sealed for SocketAddr {}
258258

259-
#[doc(cfg(any(target_os = "android", target_os = "linux")))]
260-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
259+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
260+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
261261
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
262262
impl linux_ext::addr::SocketAddrExt for SocketAddr {
263263
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");
@@ -425,7 +429,7 @@ fn abstract_namespace_not_allowed_connect() {
425429
assert!(UnixStream::connect("\0asdf").is_err());
426430
}
427431

428-
#[cfg(any(target_os = "android", target_os = "linux"))]
432+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
429433
#[test]
430434
fn test_abstract_stream_connect() {
431435
let msg1 = b"hello";
@@ -456,7 +460,7 @@ fn test_abstract_stream_connect() {
456460
thread.join().unwrap();
457461
}
458462

459-
#[cfg(any(target_os = "android", target_os = "linux"))]
463+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
460464
#[test]
461465
fn test_abstract_stream_iter() {
462466
let addr = or_panic!(SocketAddr::from_abstract_name(b"hidden"));
@@ -478,7 +482,7 @@ fn test_abstract_stream_iter() {
478482
thread.join().unwrap();
479483
}
480484

481-
#[cfg(any(target_os = "android", target_os = "linux"))]
485+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
482486
#[test]
483487
fn test_abstract_datagram_bind_send_to_addr() {
484488
let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns1"));
@@ -499,7 +503,7 @@ fn test_abstract_datagram_bind_send_to_addr() {
499503
assert_eq!(addr.as_abstract_name().unwrap(), b"ns1");
500504
}
501505

502-
#[cfg(any(target_os = "android", target_os = "linux"))]
506+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
503507
#[test]
504508
fn test_abstract_datagram_connect_addr() {
505509
let addr1 = or_panic!(SocketAddr::from_abstract_name(b"ns3"));
@@ -524,7 +528,7 @@ fn test_abstract_datagram_connect_addr() {
524528
or_panic!(bsock2.recv_from(&mut buf));
525529
}
526530

527-
#[cfg(any(target_os = "android", target_os = "linux"))]
531+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
528532
#[test]
529533
fn test_abstract_name_too_long() {
530534
match SocketAddr::from_abstract_name(
@@ -538,7 +542,7 @@ fn test_abstract_name_too_long() {
538542
}
539543
}
540544

541-
#[cfg(any(target_os = "android", target_os = "linux"))]
545+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
542546
#[test]
543547
fn test_abstract_no_pathname_and_not_unnamed() {
544548
let name = b"local";
@@ -669,7 +673,7 @@ fn test_send_vectored_fds_unix_stream() {
669673
}
670674
}
671675

672-
#[cfg(any(target_os = "android", target_os = "linux"))]
676+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
673677
#[test]
674678
#[cfg_attr(target_os = "android", ignore)] // Android SELinux rules prevent creating Unix sockets
675679
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
@@ -468,12 +468,12 @@ impl Socket {
468468
Ok(raw != 0)
469469
}
470470

471-
#[cfg(any(target_os = "android", target_os = "linux",))]
471+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
472472
pub fn set_quickack(&self, quickack: bool) -> io::Result<()> {
473473
setsockopt(self, libc::IPPROTO_TCP, libc::TCP_QUICKACK, quickack as c_int)
474474
}
475475

476-
#[cfg(any(target_os = "android", target_os = "linux",))]
476+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
477477
pub fn quickack(&self) -> io::Result<bool> {
478478
let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_QUICKACK)?;
479479
Ok(raw != 0)
@@ -537,12 +537,12 @@ impl Socket {
537537
Ok(raw != 0)
538538
}
539539

540-
#[cfg(any(target_os = "android", target_os = "linux",))]
540+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
541541
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
542542
setsockopt(self, libc::SOL_SOCKET, libc::SO_PASSCRED, passcred as libc::c_int)
543543
}
544544

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

0 commit comments

Comments
 (0)