Skip to content

Commit daf64ce

Browse files
committed
Revert back to winapi dependency
As noted in <#308>, switching from winapi to windows-sys was a breaking change as we expose some of the winapi types that are different in windows-sys. This reverts the following commits: * "Relax windows-sys dependency version" 81056b9. * "Support Socket::(set_)recv_tos on Windows" 242e087. * "Replace winapi with windows-sys" aeb6c2d. We'll make this switch in v0.5 instead.
1 parent e5e7c19 commit daf64ce

File tree

8 files changed

+171
-171
lines changed

8 files changed

+171
-171
lines changed

Cargo.toml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,8 @@ features = ["all"]
3535
[target."cfg(unix)".dependencies]
3636
libc = "0.2.124"
3737

38-
[target.'cfg(windows)'.dependencies.windows-sys]
39-
version = "0.36"
40-
features = [
41-
"Win32_Foundation",
42-
"Win32_Networking_WinSock",
43-
"Win32_System_IO",
44-
"Win32_System_WindowsProgramming",
45-
]
38+
[target."cfg(windows)".dependencies]
39+
winapi = { version = "0.3.9", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
4640

4741
[features]
4842
# Enable all API, even ones not available on all OSs.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ macro_rules! impl_debug {
7878
$(#[$target: meta])*
7979
// The flag(s) to check.
8080
// Need to specific the libc crate because Windows doesn't use
81-
// `libc` but `windows_sys`.
81+
// `libc` but `winapi`.
8282
$libc: ident :: $flag: ident
8383
),+ $(,)*
8484
) => {

src/sockaddr.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use std::mem::{self, size_of, MaybeUninit};
22
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
33
use std::{fmt, io};
44

5-
#[cfg(windows)]
6-
use windows_sys::Win32::Networking::WinSock::SOCKADDR_IN6_0;
7-
85
use crate::sys::{
96
sa_family_t, sockaddr, sockaddr_in, sockaddr_in6, sockaddr_storage, socklen_t, AF_INET,
107
AF_INET6,
118
};
9+
#[cfg(windows)]
10+
use winapi::shared::ws2ipdef::SOCKADDR_IN6_LH_u;
1211

1312
/// The address of a socket.
1413
///
@@ -185,7 +184,7 @@ impl SockAddr {
185184
addr.sin6_scope_id,
186185
#[cfg(windows)]
187186
unsafe {
188-
addr.Anonymous.sin6_scope_id
187+
*addr.u.sin6_scope_id()
189188
},
190189
)))
191190
} else {
@@ -251,6 +250,13 @@ impl From<SocketAddrV4> for SockAddr {
251250

252251
impl From<SocketAddrV6> for SockAddr {
253252
fn from(addr: SocketAddrV6) -> SockAddr {
253+
#[cfg(windows)]
254+
let u = unsafe {
255+
let mut u = mem::zeroed::<SOCKADDR_IN6_LH_u>();
256+
*u.sin6_scope_id_mut() = addr.scope_id();
257+
u
258+
};
259+
254260
let sockaddr_in6 = sockaddr_in6 {
255261
sin6_family: AF_INET6 as sa_family_t,
256262
sin6_port: addr.port().to_be(),
@@ -259,9 +265,7 @@ impl From<SocketAddrV6> for SockAddr {
259265
#[cfg(unix)]
260266
sin6_scope_id: addr.scope_id(),
261267
#[cfg(windows)]
262-
Anonymous: SOCKADDR_IN6_0 {
263-
sin6_scope_id: addr.scope_id(),
264-
},
268+
u,
265269
#[cfg(any(
266270
target_os = "dragonfly",
267271
target_os = "freebsd",

src/socket.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ impl Socket {
14011401
target_os = "openbsd",
14021402
target_os = "redox",
14031403
target_os = "solaris",
1404+
target_os = "windows",
14041405
)))]
14051406
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
14061407
let recv_tos = if recv_tos { 1 } else { 0 };
@@ -1427,6 +1428,7 @@ impl Socket {
14271428
target_os = "openbsd",
14281429
target_os = "redox",
14291430
target_os = "solaris",
1431+
target_os = "windows",
14301432
)))]
14311433
pub fn recv_tos(&self) -> io::Result<bool> {
14321434
unsafe {

src/sockref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ where
128128
/// See the `From<&impl AsRawFd>` implementation.
129129
fn from(socket: &'s S) -> Self {
130130
let socket = socket.as_raw_socket();
131-
assert!(socket != windows_sys::Win32::Networking::WinSock::INVALID_SOCKET as _);
131+
assert!(socket != winapi::um::winsock2::INVALID_SOCKET as _);
132132
SockRef {
133133
socket: ManuallyDrop::new(unsafe { Socket::from_raw_socket(socket) }),
134134
_lifetime: PhantomData,

src/sys/unix.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ macro_rules! syscall {
175175

176176
/// Maximum size of a buffer passed to system call like `recv` and `send`.
177177
#[cfg(not(target_vendor = "apple"))]
178-
const MAX_BUF_LEN: usize = ssize_t::MAX as usize;
178+
const MAX_BUF_LEN: usize = <ssize_t>::max_value() as usize;
179179

180180
// The maximum read limit on most posix-like systems is `SSIZE_MAX`, with the
181181
// man page quoting that if the count of bytes to read is greater than
@@ -186,7 +186,7 @@ const MAX_BUF_LEN: usize = ssize_t::MAX as usize;
186186
// than or equal to INT_MAX. To handle both of these the read size is capped on
187187
// both platforms.
188188
#[cfg(target_vendor = "apple")]
189-
const MAX_BUF_LEN: usize = c_int::MAX as usize - 1;
189+
const MAX_BUF_LEN: usize = <c_int>::max_value() as usize - 1;
190190

191191
#[cfg(any(
192192
all(
@@ -623,7 +623,7 @@ pub(crate) fn poll_connect(socket: &crate::Socket, timeout: Duration) -> io::Res
623623
}
624624

625625
let timeout = (timeout - elapsed).as_millis();
626-
let timeout = clamp(timeout, 1, c_int::MAX as u128) as c_int;
626+
let timeout = clamp(timeout, 1, c_int::max_value() as u128) as c_int;
627627

628628
match syscall!(poll(&mut pollfd, 1, timeout)) {
629629
Ok(0) => return Err(io::ErrorKind::TimedOut.into()),
@@ -879,7 +879,7 @@ fn into_timeval(duration: Option<Duration>) -> libc::timeval {
879879
// https://github.com/rust-lang/libc/issues/1848
880880
#[cfg_attr(target_env = "musl", allow(deprecated))]
881881
Some(duration) => libc::timeval {
882-
tv_sec: min(duration.as_secs(), libc::time_t::MAX as u64) as libc::time_t,
882+
tv_sec: min(duration.as_secs(), libc::time_t::max_value() as u64) as libc::time_t,
883883
tv_usec: duration.subsec_micros() as libc::suseconds_t,
884884
},
885885
None => libc::timeval {
@@ -932,7 +932,7 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
932932

933933
#[cfg(not(any(target_os = "haiku", target_os = "openbsd")))]
934934
fn into_secs(duration: Duration) -> c_int {
935-
min(duration.as_secs(), c_int::MAX as u64) as c_int
935+
min(duration.as_secs(), c_int::max_value() as u64) as c_int
936936
}
937937

938938
/// Add `flag` to the current set flags of `F_GETFD`.

0 commit comments

Comments
 (0)