Skip to content

Commit

Permalink
Changed socket usage to support windows
Browse files Browse the repository at this point in the history
  • Loading branch information
manforowicz committed Jun 7, 2024
1 parent 17af098 commit 00c096d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions gday_hole_punch/src/hole_puncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ fn get_local_socket(local_addr: SocketAddr) -> std::io::Result<TcpSocket> {
let sock = SockRef::from(&socket);

let _ = sock.set_reuse_address(true);

// socket2 only supports this method on these systems
#[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))]
let _ = sock.set_reuse_port(true);

let keepalive = TcpKeepalive::new()
.with_time(Duration::from_secs(5))
.with_interval(Duration::from_secs(2))
.with_retries(5);
.with_time(Duration::from_secs(60))
.with_interval(Duration::from_secs(10));
let _ = sock.set_tcp_keepalive(&keepalive);

socket.bind(local_addr)?;
Expand Down
5 changes: 4 additions & 1 deletion gday_hole_punch/src/server_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,16 @@ impl ServerStream {
/// So that this socket can be reused for
/// hole-punching.
fn enable_reuse(&self) {
let stream = match self {
let stream: &TcpStream = match self {
Self::TCP(stream) => stream,
Self::TLS(stream) => stream.get_ref(),
};

let sock = SockRef::from(stream);
let _ = sock.set_reuse_address(true);

// socket2 only supports this method on these systems
#[cfg(all(unix, not(any(target_os = "solaris", target_os = "illumos"))))]
let _ = sock.set_reuse_port(true);
}
}
Expand Down
3 changes: 1 addition & 2 deletions gday_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ async fn get_tcp_listener(addr: impl ToSocketAddrs + Display) -> TcpListener {
// sets the keepalive to 10 minutes
let tcp_keepalive = TcpKeepalive::new()
.with_time(Duration::from_secs(600))
.with_interval(Duration::from_secs(10))
.with_retries(3);
.with_interval(Duration::from_secs(10));
let socket = SockRef::from(&listener);
socket
.set_tcp_keepalive(&tcp_keepalive)
Expand Down

0 comments on commit 00c096d

Please sign in to comment.