Skip to content

Commit

Permalink
Bump windows sys and add support for retries
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Mattix II <keithmattix@microsoft.com>
  • Loading branch information
keithmattix committed Feb 21, 2025
1 parent 07e7b67 commit 9b9d47c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ targets = [
"x86_64-apple-darwin",
"x86_64-pc-solaris",
"x86_64-pc-windows-msvc",
"x86_64-pc-windows-gnu",
"x86_64-unknown-freebsd",
"x86_64-unknown-fuchsia",
"x86_64-unknown-illumos",
Expand All @@ -54,7 +55,7 @@ features = ["all"]
libc = "0.2.150"

[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.62"
version = "0.59"
features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
Expand Down
21 changes: 18 additions & 3 deletions src/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub(crate) const SOCK_SEQPACKET: c_int =
pub(crate) use windows_sys::Win32::Networking::WinSock::{
IPPROTO_ICMP, IPPROTO_ICMPV6, IPPROTO_TCP, IPPROTO_UDP,
};

pub(crate) use windows_sys::Win32::Networking::WinSock::TCP_KEEPCNT;
// Used in `SockAddr`.
pub(crate) use windows_sys::Win32::Networking::WinSock::{
SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in, SOCKADDR_IN6 as sockaddr_in6,
Expand Down Expand Up @@ -727,17 +729,24 @@ fn into_ms(duration: Option<Duration>) -> u32 {
}

pub(crate) fn set_tcp_keepalive(socket: Socket, keepalive: &TcpKeepalive) -> io::Result<()> {
let mut keepalive = tcp_keepalive {
let mut w_keepalive = tcp_keepalive {
onoff: 1,
keepalivetime: into_ms(keepalive.time),
keepaliveinterval: into_ms(keepalive.interval),
};


if let Some(retries) = keepalive.retries {
unsafe {
setsockopt(socket, WinSock::IPPROTO_TCP, WinSock::TCP_KEEPCNT, retries as c_int)?
}
}
let mut out = 0;
syscall!(
WSAIoctl(
socket,
SIO_KEEPALIVE_VALS,
&mut keepalive as *mut _ as *mut _,
&mut w_keepalive as *mut _ as *mut _,
size_of::<tcp_keepalive>() as _,
ptr::null_mut(),
0,
Expand Down Expand Up @@ -931,7 +940,13 @@ pub(crate) fn unix_sockaddr(path: &Path) -> io::Result<SockAddr> {
storage.sun_family = crate::sys::AF_UNIX as sa_family_t;
// `storage` was initialized to zero above, so the path is
// already null terminated.
storage.sun_path[..bytes.len()].copy_from_slice(bytes);
storage.sun_path[..bytes.len()].copy_from_slice(
bytes
.iter()
.map(|b| *b as i8)
.collect::<Vec<_>>()
.as_slice(),
);

let base = storage as *const _ as usize;
let path = &storage.sun_path as *const _ as usize;
Expand Down

0 comments on commit 9b9d47c

Please sign in to comment.