Skip to content

Commit d71f29b

Browse files
BerrysoftDarksonnThomasdezeeuw
authored
Add cygwin support (#568) (#578)
Co-authored-by: Alice Ryhl <aliceryhl@google.com> Co-authored-by: Thomas de Zeeuw <thomasdezeeuw@gmail.com>
1 parent 660d5f8 commit d71f29b

File tree

5 files changed

+173
-32
lines changed

5 files changed

+173
-32
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
- sparcv9-sun-solaris
8282
- x86_64-apple-darwin
8383
- x86_64-apple-ios
84+
- x86_64-pc-cygwin
8485
- x86_64-pc-solaris
8586
# Fails with:
8687
# `rror calling dlltool 'x86_64-w64-mingw32-dlltool': No such file or

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ impl TcpKeepalive {
522522
target_os = "tvos",
523523
target_os = "watchos",
524524
target_os = "windows",
525+
target_os = "cygwin",
525526
))]
526527
#[cfg_attr(
527528
docsrs,
@@ -567,6 +568,7 @@ impl TcpKeepalive {
567568
target_os = "netbsd",
568569
target_os = "tvos",
569570
target_os = "watchos",
571+
target_os = "cygwin",
570572
)
571573
))]
572574
#[cfg_attr(

src/socket.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ impl Socket {
202202
/// non-blocking mode before calling this function), socket option can't be
203203
/// set *while connecting*. This will cause errors on Windows. Socket
204204
/// options can be safely set before and after connecting the socket.
205+
///
206+
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
207+
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`]
208+
/// (Cygwin only).
209+
#[allow(rustdoc::broken_intra_doc_links)] // Socket::set_no_peercred
205210
pub fn connect(&self, address: &SockAddr) -> io::Result<()> {
206211
sys::connect(self.as_raw(), address)
207212
}
@@ -262,6 +267,13 @@ impl Socket {
262267
/// This function sets the same flags as in done for [`Socket::new`],
263268
/// [`Socket::accept_raw`] can be used if you don't want to set those flags.
264269
#[doc = man_links!(accept(2))]
270+
///
271+
/// # Notes
272+
///
273+
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
274+
/// it. If the behavior is not expected, try [`Socket::set_no_peercred`]
275+
/// (Cygwin only).
276+
#[allow(rustdoc::broken_intra_doc_links)] // Socket::set_no_peercred
265277
pub fn accept(&self) -> io::Result<(Socket, SockAddr)> {
266278
// Use `accept4` on platforms that support it.
267279
#[cfg(any(
@@ -273,6 +285,7 @@ impl Socket {
273285
target_os = "linux",
274286
target_os = "netbsd",
275287
target_os = "openbsd",
288+
target_os = "cygwin",
276289
))]
277290
return self._accept4(libc::SOCK_CLOEXEC);
278291

@@ -286,6 +299,7 @@ impl Socket {
286299
target_os = "linux",
287300
target_os = "netbsd",
288301
target_os = "openbsd",
302+
target_os = "cygwin",
289303
)))]
290304
{
291305
let (socket, addr) = self.accept_raw()?;
@@ -765,6 +779,7 @@ const fn set_common_type(ty: Type) -> Type {
765779
target_os = "linux",
766780
target_os = "netbsd",
767781
target_os = "openbsd",
782+
target_os = "cygwin",
768783
))]
769784
let ty = ty._cloexec();
770785

@@ -794,6 +809,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
794809
target_os = "openbsd",
795810
target_os = "espidf",
796811
target_os = "vita",
812+
target_os = "cygwin",
797813
))
798814
))]
799815
socket._set_cloexec(true)?;
@@ -971,8 +987,8 @@ impl Socket {
971987
/// For more information about this option, see [`set_passcred`].
972988
///
973989
/// [`set_passcred`]: Socket::set_passcred
974-
#[cfg(all(unix, target_os = "linux"))]
975-
#[cfg_attr(docsrs, doc(cfg(all(unix, target_os = "linux"))))]
990+
#[cfg(any(target_os = "linux", target_os = "cygwin"))]
991+
#[cfg_attr(docsrs, doc(cfg(any(target_os = "linux", target_os = "cygwin"))))]
976992
pub fn passcred(&self) -> io::Result<bool> {
977993
unsafe {
978994
getsockopt::<c_int>(self.as_raw(), sys::SOL_SOCKET, sys::SO_PASSCRED)
@@ -984,8 +1000,8 @@ impl Socket {
9841000
///
9851001
/// If this option is enabled, enables the receiving of the `SCM_CREDENTIALS`
9861002
/// control messages.
987-
#[cfg(all(unix, target_os = "linux"))]
988-
#[cfg_attr(docsrs, doc(cfg(all(unix, target_os = "linux"))))]
1003+
#[cfg(any(target_os = "linux", target_os = "cygwin"))]
1004+
#[cfg_attr(docsrs, doc(cfg(any(target_os = "linux", target_os = "cygwin"))))]
9891005
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
9901006
unsafe {
9911007
setsockopt(
@@ -1306,6 +1322,7 @@ impl Socket {
13061322
target_os = "nto",
13071323
target_os = "espidf",
13081324
target_os = "vita",
1325+
target_os = "cygwin",
13091326
)))]
13101327
pub fn join_multicast_v4_n(
13111328
&self,
@@ -1339,6 +1356,7 @@ impl Socket {
13391356
target_os = "nto",
13401357
target_os = "espidf",
13411358
target_os = "vita",
1359+
target_os = "cygwin",
13421360
)))]
13431361
pub fn leave_multicast_v4_n(
13441362
&self,
@@ -1631,6 +1649,7 @@ impl Socket {
16311649
target_os = "nto",
16321650
target_os = "espidf",
16331651
target_os = "vita",
1652+
target_os = "cygwin",
16341653
)))]
16351654
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
16361655
unsafe {
@@ -1662,6 +1681,7 @@ impl Socket {
16621681
target_os = "nto",
16631682
target_os = "espidf",
16641683
target_os = "vita",
1684+
target_os = "cygwin",
16651685
)))]
16661686
pub fn recv_tos(&self) -> io::Result<bool> {
16671687
unsafe {
@@ -2039,6 +2059,7 @@ impl Socket {
20392059
target_os = "hurd",
20402060
target_os = "espidf",
20412061
target_os = "vita",
2062+
target_os = "cygwin",
20422063
))
20432064
))]
20442065
pub fn recv_hoplimit_v6(&self) -> io::Result<bool> {
@@ -2067,6 +2088,7 @@ impl Socket {
20672088
target_os = "hurd",
20682089
target_os = "espidf",
20692090
target_os = "vita",
2091+
target_os = "cygwin",
20702092
))
20712093
))]
20722094
pub fn set_recv_hoplimit_v6(&self, recv_hoplimit: bool) -> io::Result<()> {
@@ -2136,6 +2158,7 @@ impl Socket {
21362158
target_os = "netbsd",
21372159
target_os = "tvos",
21382160
target_os = "watchos",
2161+
target_os = "cygwin",
21392162
)
21402163
))]
21412164
#[cfg_attr(
@@ -2185,6 +2208,7 @@ impl Socket {
21852208
target_os = "netbsd",
21862209
target_os = "tvos",
21872210
target_os = "watchos",
2211+
target_os = "cygwin",
21882212
)
21892213
))]
21902214
#[cfg_attr(

0 commit comments

Comments
 (0)