Skip to content

Commit 0616edc

Browse files
authored
Rollup merge of rust-lang#139524 - Berrysoft:cygwin-socket-ext, r=tgross35
Add socket extensions for cygwin r? `@joboet` * Abstract name uds addr * quickack * passcred
2 parents 67fff93 + feb1c59 commit 0616edc

File tree

12 files changed

+131
-57
lines changed

12 files changed

+131
-57
lines changed

std/src/os/cygwin/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Cygwin-specific definitions
22
#![stable(feature = "raw_ext", since = "1.1.0")]
33
pub mod fs;
4+
pub mod net;
45
pub(crate) mod raw;

std/src/os/cygwin/net.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Cygwin-specific networking functionality.
2+
//!
3+
//! There are some limitations of Unix domain sockets on Cygwin:
4+
//! * The syscalls `accept` and `connect` need
5+
//! [handshake](https://inbox.sourceware.org/cygwin/[email protected]/T/#t).
6+
//! * Cannot bind to abstract addr.
7+
//! * Unbounded unix socket has an abstract local addr.
8+
//! * Doesn't support recvmsg with control data.
9+
10+
#![stable(feature = "unix_socket_abstract", since = "1.70.0")]
11+
12+
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
13+
pub use crate::os::net::linux_ext::addr::SocketAddrExt;
14+
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
15+
pub use crate::os::net::linux_ext::socket::UnixSocketExt;
16+
#[stable(feature = "tcp_quickack", since = "1.89.0")]
17+
pub use crate::os::net::linux_ext::tcp::TcpStreamExt;

std/src/os/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,5 @@ pub mod xous;
185185
#[cfg(any(unix, target_os = "hermit", target_os = "trusty", target_os = "wasi", doc))]
186186
pub mod fd;
187187

188-
#[cfg(any(target_os = "linux", target_os = "android", doc))]
188+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
189189
mod net;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Linux and Android-specific networking functionality.
1+
//! Linux, Android and Cygwin-specific networking functionality.
22
3-
#![doc(cfg(any(target_os = "linux", target_os = "android")))]
3+
#![doc(cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin")))]
44

55
#[stable(feature = "unix_socket_abstract", since = "1.70.0")]
66
pub(crate) mod addr;

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;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::bstr::ByteStr;
22
use crate::ffi::OsStr;
3-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
3+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
44
use crate::os::net::linux_ext;
55
use crate::os::unix::ffi::OsStrExt;
66
use crate::path::Path;
@@ -241,7 +241,7 @@ impl SocketAddr {
241241

242242
// macOS seems to return a len of 16 and a zeroed sun_path for unnamed addresses
243243
if len == 0
244-
|| (cfg!(not(any(target_os = "linux", target_os = "android")))
244+
|| (cfg!(not(any(target_os = "linux", target_os = "android", target_os = "cygwin")))
245245
&& self.addr.sun_path[0] == 0)
246246
{
247247
AddressKind::Unnamed
@@ -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]> {

std/src/os/unix/net/ancillary.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use crate::sys::net::Socket;
1616
not(target_os = "linux"),
1717
not(target_os = "android"),
1818
not(target_os = "netbsd"),
19-
not(target_os = "freebsd")
19+
not(target_os = "freebsd"),
20+
not(target_os = "cygwin"),
2021
))]
2122
#[allow(non_camel_case_types)]
2223
mod libc {
@@ -195,14 +196,15 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> {
195196
not(target_os = "android"),
196197
not(target_os = "linux"),
197198
not(target_os = "netbsd"),
198-
not(target_os = "freebsd")
199+
not(target_os = "freebsd"),
200+
not(target_os = "cygwin"),
199201
))]
200202
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
201203
#[derive(Clone)]
202204
pub struct SocketCred(());
203205

204206
/// Unix credential.
205-
#[cfg(any(target_os = "android", target_os = "linux",))]
207+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
206208
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
207209
#[derive(Clone)]
208210
pub struct SocketCred(libc::ucred);
@@ -217,8 +219,8 @@ pub struct SocketCred(libc::sockcred);
217219
#[derive(Clone)]
218220
pub struct SocketCred(libc::sockcred2);
219221

220-
#[doc(cfg(any(target_os = "android", target_os = "linux")))]
221-
#[cfg(any(target_os = "android", target_os = "linux"))]
222+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
223+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
222224
impl SocketCred {
223225
/// Creates a Unix credential struct.
224226
///
@@ -407,15 +409,16 @@ impl<'a> Iterator for ScmRights<'a> {
407409
not(target_os = "android"),
408410
not(target_os = "linux"),
409411
not(target_os = "netbsd"),
410-
not(target_os = "freebsd")
412+
not(target_os = "freebsd"),
413+
not(target_os = "cygwin"),
411414
))]
412415
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
413416
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, ()>);
414417

415418
/// This control message contains unix credentials.
416419
///
417420
/// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_CREDENTIALS` or `SCM_CREDS`.
418-
#[cfg(any(target_os = "android", target_os = "linux",))]
421+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
419422
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
420423
pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>);
421424

@@ -432,7 +435,8 @@ pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::sockcred>);
432435
target_os = "android",
433436
target_os = "linux",
434437
target_os = "netbsd",
435-
target_os = "freebsd"
438+
target_os = "freebsd",
439+
target_os = "cygwin",
436440
))]
437441
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
438442
impl<'a> Iterator for ScmCredentials<'a> {
@@ -460,7 +464,8 @@ pub enum AncillaryData<'a> {
460464
target_os = "android",
461465
target_os = "linux",
462466
target_os = "netbsd",
463-
target_os = "freebsd"
467+
target_os = "freebsd",
468+
target_os = "cygwin",
464469
))]
465470
ScmCredentials(ScmCredentials<'a>),
466471
}
@@ -489,7 +494,8 @@ impl<'a> AncillaryData<'a> {
489494
target_os = "android",
490495
target_os = "linux",
491496
target_os = "netbsd",
492-
target_os = "freebsd"
497+
target_os = "freebsd",
498+
target_os = "cygwin",
493499
))]
494500
unsafe fn as_credentials(data: &'a [u8]) -> Self {
495501
let ancillary_data_iter = AncillaryDataIter::new(data);
@@ -507,7 +513,7 @@ impl<'a> AncillaryData<'a> {
507513
match (*cmsg).cmsg_level {
508514
libc::SOL_SOCKET => match (*cmsg).cmsg_type {
509515
libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)),
510-
#[cfg(any(target_os = "android", target_os = "linux",))]
516+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))]
511517
libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)),
512518
#[cfg(target_os = "freebsd")]
513519
libc::SCM_CREDS2 => Ok(AncillaryData::as_credentials(data)),
@@ -729,7 +735,8 @@ impl<'a> SocketAncillary<'a> {
729735
target_os = "android",
730736
target_os = "linux",
731737
target_os = "netbsd",
732-
target_os = "freebsd"
738+
target_os = "freebsd",
739+
target_os = "cygwin",
733740
))]
734741
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
735742
pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool {

std/src/os/unix/net/datagram.rs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use libc::MSG_NOSIGNAL;
1515

1616
use super::{SocketAddr, sockaddr_un};
17-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
17+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
1818
use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to};
19-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
19+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
2020
use crate::io::{IoSlice, IoSliceMut};
2121
use crate::net::Shutdown;
2222
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
@@ -397,8 +397,14 @@ impl UnixDatagram {
397397
///
398398
/// # Examples
399399
///
400-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
401-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
400+
#[cfg_attr(
401+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
402+
doc = "```no_run"
403+
)]
404+
#[cfg_attr(
405+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
406+
doc = "```ignore"
407+
)]
402408
/// #![feature(unix_socket_ancillary_data)]
403409
/// use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
404410
/// use std::io::IoSliceMut;
@@ -428,7 +434,7 @@ impl UnixDatagram {
428434
/// Ok(())
429435
/// }
430436
/// ```
431-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
437+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
432438
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
433439
pub fn recv_vectored_with_ancillary_from(
434440
&self,
@@ -447,8 +453,14 @@ impl UnixDatagram {
447453
///
448454
/// # Examples
449455
///
450-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
451-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
456+
#[cfg_attr(
457+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
458+
doc = "```no_run"
459+
)]
460+
#[cfg_attr(
461+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
462+
doc = "```ignore"
463+
)]
452464
/// #![feature(unix_socket_ancillary_data)]
453465
/// use std::os::unix::net::{UnixDatagram, SocketAncillary, AncillaryData};
454466
/// use std::io::IoSliceMut;
@@ -478,7 +490,7 @@ impl UnixDatagram {
478490
/// Ok(())
479491
/// }
480492
/// ```
481-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
493+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
482494
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
483495
pub fn recv_vectored_with_ancillary(
484496
&self,
@@ -588,8 +600,14 @@ impl UnixDatagram {
588600
///
589601
/// # Examples
590602
///
591-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
592-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
603+
#[cfg_attr(
604+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
605+
doc = "```no_run"
606+
)]
607+
#[cfg_attr(
608+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
609+
doc = "```ignore"
610+
)]
593611
/// #![feature(unix_socket_ancillary_data)]
594612
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
595613
/// use std::io::IoSlice;
@@ -613,7 +631,7 @@ impl UnixDatagram {
613631
/// Ok(())
614632
/// }
615633
/// ```
616-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
634+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
617635
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
618636
pub fn send_vectored_with_ancillary_to<P: AsRef<Path>>(
619637
&self,
@@ -630,8 +648,14 @@ impl UnixDatagram {
630648
///
631649
/// # Examples
632650
///
633-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
634-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
651+
#[cfg_attr(
652+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
653+
doc = "```no_run"
654+
)]
655+
#[cfg_attr(
656+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
657+
doc = "```ignore"
658+
)]
635659
/// #![feature(unix_socket_ancillary_data)]
636660
/// use std::os::unix::net::{UnixDatagram, SocketAncillary};
637661
/// use std::io::IoSlice;
@@ -655,7 +679,7 @@ impl UnixDatagram {
655679
/// Ok(())
656680
/// }
657681
/// ```
658-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
682+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
659683
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
660684
pub fn send_vectored_with_ancillary(
661685
&self,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#![stable(feature = "unix_socket", since = "1.10.0")]
55

66
mod addr;
7-
#[doc(cfg(any(target_os = "android", target_os = "linux")))]
8-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
7+
#[doc(cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin")))]
8+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
99
mod ancillary;
1010
mod datagram;
1111
mod listener;
@@ -27,7 +27,7 @@ mod ucred;
2727

2828
#[stable(feature = "unix_socket", since = "1.10.0")]
2929
pub use self::addr::*;
30-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
30+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
3131
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
3232
pub use self::ancillary::*;
3333
#[stable(feature = "unix_socket", since = "1.10.0")]

std/src/os/unix/net/stream.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ cfg_select! {
1616
}
1717

1818
use super::{SocketAddr, sockaddr_un};
19-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
19+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
2020
use super::{SocketAncillary, recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to};
2121
#[cfg(any(
2222
target_os = "android",
@@ -508,8 +508,14 @@ impl UnixStream {
508508
///
509509
/// # Examples
510510
///
511-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
512-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
511+
#[cfg_attr(
512+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
513+
doc = "```no_run"
514+
)]
515+
#[cfg_attr(
516+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
517+
doc = "```ignore"
518+
)]
513519
/// #![feature(unix_socket_ancillary_data)]
514520
/// use std::os::unix::net::{UnixStream, SocketAncillary, AncillaryData};
515521
/// use std::io::IoSliceMut;
@@ -539,7 +545,7 @@ impl UnixStream {
539545
/// Ok(())
540546
/// }
541547
/// ```
542-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
548+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
543549
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
544550
pub fn recv_vectored_with_ancillary(
545551
&self,
@@ -557,8 +563,14 @@ impl UnixStream {
557563
///
558564
/// # Examples
559565
///
560-
#[cfg_attr(any(target_os = "android", target_os = "linux"), doc = "```no_run")]
561-
#[cfg_attr(not(any(target_os = "android", target_os = "linux")), doc = "```ignore")]
566+
#[cfg_attr(
567+
any(target_os = "android", target_os = "linux", target_os = "cygwin"),
568+
doc = "```no_run"
569+
)]
570+
#[cfg_attr(
571+
not(any(target_os = "android", target_os = "linux", target_os = "cygwin")),
572+
doc = "```ignore"
573+
)]
562574
/// #![feature(unix_socket_ancillary_data)]
563575
/// use std::os::unix::net::{UnixStream, SocketAncillary};
564576
/// use std::io::IoSlice;
@@ -582,7 +594,7 @@ impl UnixStream {
582594
/// Ok(())
583595
/// }
584596
/// ```
585-
#[cfg(any(doc, target_os = "android", target_os = "linux"))]
597+
#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "cygwin"))]
586598
#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")]
587599
pub fn send_vectored_with_ancillary(
588600
&self,

0 commit comments

Comments
 (0)