Skip to content

Commit

Permalink
Backport redox compilation to 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 authored and Thomasdezeeuw committed Dec 9, 2020
1 parent 3b4214d commit a0053b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ all-features = true
version = "0.3.3"
features = ["handleapi", "ws2def", "ws2ipdef", "ws2tcpip", "minwindef"]

[target."cfg(any(unix, target_os = \"redox\"))".dependencies]
[target."cfg(unix)".dependencies]
cfg-if = "1.0"
libc = { version = "0.2.66", features = ["align"] }

[target."cfg(target_os = \"redox\")".dependencies]
redox_syscall = "0.1.38"

[dev-dependencies]
tempdir = "0.3"

Expand Down
4 changes: 2 additions & 2 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl Socket {
///
/// The `TCP_MAXSEG` option denotes the TCP Maximum Segment
/// Size and is only available on TCP sockets.
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "redox")))]
pub fn mss(&self) -> io::Result<u32> {
self.inner.mss()
}
Expand All @@ -382,7 +382,7 @@ impl Socket {
///
/// The `TCP_MAXSEG` option denotes the TCP Maximum Segment
/// Size and is only available on TCP sockets.
#[cfg(unix)]
#[cfg(all(unix, not(target_os = "redox")))]
pub fn set_mss(&self, mss: u32) -> io::Result<()> {
self.inner.set_mss(mss)
}
Expand Down
9 changes: 7 additions & 2 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub use libc::c_int;
// Used in `Domain`.
pub(crate) use libc::{AF_INET, AF_INET6};
// Used in `Type`.
pub(crate) use libc::{SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET, SOCK_STREAM};
#[cfg(not(target_os = "redox"))]
pub(crate) use libc::SOCK_RAW;
pub(crate) use libc::{SOCK_DGRAM, SOCK_SEQPACKET, SOCK_STREAM};
// Used in `Protocol`.
pub(crate) use libc::{IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_TCP, IPPROTO_UDP};

Expand Down Expand Up @@ -131,8 +133,9 @@ impl_debug!(
crate::Type,
libc::SOCK_STREAM,
libc::SOCK_DGRAM,
#[cfg(not(target_os = "redox"))]
libc::SOCK_RAW,
#[cfg(not(target_os = "haiku"))]
#[cfg(not(any(target_os = "haiku", target_os = "redox")))]
libc::SOCK_RDM,
libc::SOCK_SEQPACKET,
/* TODO: add these optional bit OR-ed flags:
Expand Down Expand Up @@ -534,13 +537,15 @@ impl Socket {
unsafe { self.setsockopt(libc::IPPROTO_IP, libc::IP_TTL, ttl as c_int) }
}

#[cfg(not(target_os = "redox"))]
pub fn mss(&self) -> io::Result<u32> {
unsafe {
let raw: c_int = self.getsockopt(libc::IPPROTO_TCP, libc::TCP_MAXSEG)?;
Ok(raw as u32)
}
}

#[cfg(not(target_os = "redox"))]
pub fn set_mss(&self, mss: u32) -> io::Result<()> {
unsafe { self.setsockopt(libc::IPPROTO_TCP, libc::TCP_MAXSEG, mss as c_int) }
}
Expand Down

0 comments on commit a0053b5

Please sign in to comment.