From 439714e15da7820909f83e92686d51df0143c330 Mon Sep 17 00:00:00 2001 From: lilo Date: Tue, 6 Feb 2024 10:41:27 +0800 Subject: [PATCH] fix: support windows building --- src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 56b36c1..e3775a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,11 +10,15 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket}, - os::unix::prelude::{FromRawFd, IntoRawFd}, sync::Arc, time::Instant, }; +#[cfg(unix)] +use std::os::unix::prelude::{FromRawFd, IntoRawFd}; +#[cfg(windows)] +use std::os::windows::prelude::{FromRawSocket, IntoRawSocket}; + #[cfg(feature = "script")] use std::path::PathBuf; @@ -107,6 +111,7 @@ fn main() -> Result<()> { socket .set_reuse_address(true) .context("failed to set_reuse_address")?; + #[cfg(unix)] socket .set_reuse_port(true) .context("failed to set_reuse_address")?; @@ -147,7 +152,7 @@ fn main() -> Result<()> { let socket = { #[cfg(windows)] unsafe { - UdpSocket::from_raw_socket(socket.into_raw_socket())? + UdpSocket::from_raw_socket(socket.into_raw_socket()) } #[cfg(unix)] unsafe {