Skip to content

Commit

Permalink
fix(shadowsocks): set_ip_unicast_if doesnt need async
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Aug 12, 2023
1 parent 34f91a9 commit 6d82932
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/shadowsocks/src/net/sys/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl TcpStream {

// Binds to a specific network interface (device)
if let Some(ref iface) = opts.bind_interface {
set_ip_unicast_if(&socket, &addr, iface).await?;
set_ip_unicast_if(&socket, &addr, iface)?;
}

set_common_sockopt_for_connect(addr, &socket, opts)?;
Expand Down Expand Up @@ -265,7 +265,7 @@ fn find_adapter_interface_index(addr: &SocketAddr, iface: &str) -> io::Result<Op
Ok(None)
}

async fn find_interface_index_cached(addr: &SocketAddr, iface: &str) -> io::Result<u32> {
fn find_interface_index_cached(addr: &SocketAddr, iface: &str) -> io::Result<u32> {
const INDEX_EXPIRE_DURATION: Duration = Duration::from_secs(5);

thread_local! {
Expand Down Expand Up @@ -308,10 +308,10 @@ async fn find_interface_index_cached(addr: &SocketAddr, iface: &str) -> io::Resu
Ok(idx)
}

async fn set_ip_unicast_if<S: AsRawSocket>(socket: &S, addr: &SocketAddr, iface: &str) -> io::Result<()> {
fn set_ip_unicast_if<S: AsRawSocket>(socket: &S, addr: &SocketAddr, iface: &str) -> io::Result<()> {
let handle = socket.as_raw_socket() as SOCKET;

let if_index = find_interface_index_cached(addr, iface).await?;
let if_index = find_interface_index_cached(addr, iface)?;

unsafe {
// https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options
Expand Down Expand Up @@ -484,7 +484,7 @@ pub async fn bind_outbound_udp_socket(bind_addr: &SocketAddr, opts: &ConnectOpts
let socket = Socket::new(Domain::for_address(*bind_addr), Type::DGRAM, Some(Protocol::UDP))?;

if let Some(ref iface) = opts.bind_interface {
set_ip_unicast_if(&socket, bind_addr, iface).await?;
set_ip_unicast_if(&socket, bind_addr, iface)?;
}

// bind() should be called after IP_UNICAST_IF
Expand Down

0 comments on commit 6d82932

Please sign in to comment.