Skip to content

Commit 9b9d47c

Browse files
committed
Bump windows sys and add support for retries
Signed-off-by: Keith Mattix II <[email protected]>
1 parent 07e7b67 commit 9b9d47c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ targets = [
3838
"x86_64-apple-darwin",
3939
"x86_64-pc-solaris",
4040
"x86_64-pc-windows-msvc",
41+
"x86_64-pc-windows-gnu",
4142
"x86_64-unknown-freebsd",
4243
"x86_64-unknown-fuchsia",
4344
"x86_64-unknown-illumos",
@@ -54,7 +55,7 @@ features = ["all"]
5455
libc = "0.2.150"
5556

5657
[target.'cfg(windows)'.dependencies.windows-sys]
57-
version = "0.62"
58+
version = "0.59"
5859
features = [
5960
"Win32_Foundation",
6061
"Win32_Networking_WinSock",

src/sys/windows.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ pub(crate) const SOCK_SEQPACKET: c_int =
5959
pub(crate) use windows_sys::Win32::Networking::WinSock::{
6060
IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_TCP, IPPROTO_UDP,
6161
};
62+
63+
pub(crate) use windows_sys::Win32::Networking::WinSock::TCP_KEEPCNT;
6264
// Used in `SockAddr`.
6365
pub(crate) use windows_sys::Win32::Networking::WinSock::{
6466
SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, SOCKADDR_IN6 as sockaddr_in6,
@@ -727,17 +729,24 @@ fn into_ms(duration: Option<Duration>) -> u32 {
727729
}
728730

729731
pub(crate) fn set_tcp_keepalive(socket: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
730-
let mut keepalive = tcp_keepalive {
732+
let mut w_keepalive = tcp_keepalive {
731733
onoff: 1,
732734
keepalivetime: into_ms(keepalive.time),
733735
keepaliveinterval: into_ms(keepalive.interval),
734736
};
737+
738+
739+
if let Some(retries) = keepalive.retries {
740+
unsafe {
741+
setsockopt(socket, WinSock::IPPROTO_TCP, WinSock::TCP_KEEPCNT, retries as c_int)?
742+
}
743+
}
735744
let mut out = 0;
736745
syscall!(
737746
WSAIoctl(
738747
socket,
739748
SIO_KEEPALIVE_VALS,
740-
&mut keepalive as *mut _ as *mut _,
749+
&mut w_keepalive as *mut _ as *mut _,
741750
size_of::<tcp_keepalive>() as _,
742751
ptr::null_mut(),
743752
0,
@@ -931,7 +940,13 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result<SockAddr> {
931940
storage.sun_family = crate::sys::AF_UNIX as sa_family_t;
932941
// `storage` was initialized to zero above, so the path is
933942
// already null terminated.
934-
storage.sun_path[..bytes.len()].copy_from_slice(bytes);
943+
storage.sun_path[..bytes.len()].copy_from_slice(
944+
bytes
945+
.iter()
946+
.map(|b| *b as i8)
947+
.collect::<Vec<_>>()
948+
.as_slice(),
949+
);
935950

936951
let base = storage as *const _ as usize;
937952
let path = &storage.sun_path as *const _ as usize;

0 commit comments

Comments
 (0)