Skip to content

Add cygwin support #568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
- sparcv9-sun-solaris
- x86_64-apple-darwin
- x86_64-apple-ios
- x86_64-pc-cygwin
- x86_64-pc-solaris
# Fails with:
# `rror calling dlltool 'x86_64-w64-mingw32-dlltool': No such file or
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl TcpKeepalive {
target_os = "tvos",
target_os = "watchos",
target_os = "windows",
target_os = "cygwin",
))]
pub const fn with_interval(self, interval: Duration) -> Self {
Self {
Expand Down Expand Up @@ -543,6 +544,7 @@ impl TcpKeepalive {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub const fn with_retries(self, retries: u32) -> Self {
Expand Down
24 changes: 22 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ impl Socket {
/// non-blocking mode before calling this function), socket option can't be
/// set *while connecting*. This will cause errors on Windows. Socket
/// options can be safely set before and after connecting the socket.
///
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
/// it. If the behavior is not expected, try `Socket::set_no_peercred`.
pub fn connect(&self, address: &SockAddr) -> io::Result<()> {
sys::connect(self.as_raw(), address)
}
Expand Down Expand Up @@ -260,6 +263,11 @@ impl Socket {
/// This function sets the same flags as in done for [`Socket::new`],
/// [`Socket::accept_raw`] can be used if you don't want to set those flags.
#[doc = man_links!(accept(2))]
///
/// # Notes
///
/// On Cygwin, a Unix domain socket connect blocks until the server accepts
/// it. If the behavior is not expected, try `Socket::set_no_peercred`.
pub fn accept(&self) -> io::Result<(Socket, SockAddr)> {
// Use `accept4` on platforms that support it.
#[cfg(any(
Expand All @@ -271,6 +279,7 @@ impl Socket {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
return self._accept4(libc::SOCK_CLOEXEC);

Expand All @@ -284,6 +293,7 @@ impl Socket {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))]
{
let (socket, addr) = self.accept_raw()?;
Expand Down Expand Up @@ -752,6 +762,7 @@ const fn set_common_type(ty: Type) -> Type {
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
let ty = ty._cloexec();

Expand Down Expand Up @@ -781,6 +792,7 @@ fn set_common_flags(socket: Socket) -> io::Result<Socket> {
target_os = "openbsd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
socket._set_cloexec(true)?;
Expand Down Expand Up @@ -956,7 +968,7 @@ impl Socket {
/// For more information about this option, see [`set_passcred`].
///
/// [`set_passcred`]: Socket::set_passcred
#[cfg(all(unix, target_os = "linux"))]
#[cfg(all(unix, any(target_os = "linux", target_os = "cygwin")))]
pub fn passcred(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::SOL_SOCKET, sys::SO_PASSCRED)
Expand All @@ -968,7 +980,7 @@ impl Socket {
///
/// If this option is enabled, enables the receiving of the `SCM_CREDENTIALS`
/// control messages.
#[cfg(all(unix, target_os = "linux"))]
#[cfg(all(unix, any(target_os = "linux", target_os = "cygwin")))]
pub fn set_passcred(&self, passcred: bool) -> io::Result<()> {
unsafe {
setsockopt(
Expand Down Expand Up @@ -1254,6 +1266,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn join_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1287,6 +1300,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn leave_multicast_v4_n(
&self,
Expand Down Expand Up @@ -1577,6 +1591,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn set_recv_tos_v4(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
Expand Down Expand Up @@ -1608,6 +1623,7 @@ impl Socket {
target_os = "nto",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
)))]
pub fn recv_tos_v4(&self) -> io::Result<bool> {
unsafe {
Expand Down Expand Up @@ -1978,6 +1994,7 @@ impl Socket {
target_os = "hurd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
pub fn recv_hoplimit_v6(&self) -> io::Result<bool> {
Expand Down Expand Up @@ -2006,6 +2023,7 @@ impl Socket {
target_os = "hurd",
target_os = "espidf",
target_os = "vita",
target_os = "cygwin",
))
))]
pub fn set_recv_hoplimit_v6(&self, recv_hoplimit: bool) -> io::Result<()> {
Expand Down Expand Up @@ -2063,6 +2081,7 @@ impl Socket {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub fn keepalive_interval(&self) -> io::Result<Duration> {
Expand Down Expand Up @@ -2092,6 +2111,7 @@ impl Socket {
target_os = "netbsd",
target_os = "tvos",
target_os = "watchos",
target_os = "cygwin",
)
))]
pub fn keepalive_retries(&self) -> io::Result<u32> {
Expand Down
Loading