diff --git a/crates/shadowsocks-service/src/local/tun/tcp.rs b/crates/shadowsocks-service/src/local/tun/tcp.rs index b5b22d9f3ba1..4042a3d2184d 100644 --- a/crates/shadowsocks-service/src/local/tun/tcp.rs +++ b/crates/shadowsocks-service/src/local/tun/tcp.rs @@ -17,7 +17,7 @@ use std::{ use log::{debug, error, trace}; use shadowsocks::{net::TcpSocketOpts, relay::socks5::Address}; use smoltcp::{ - iface::{Config as InterfaceConfig, Interface, SocketHandle, SocketSet}, + iface::{Config as InterfaceConfig, Interface, PollResult, SocketHandle, SocketSet}, phy::{DeviceCapabilities, Medium}, socket::tcp::{Socket as TcpSocket, SocketBuffer as TcpSocketBuffer, State as TcpState}, storage::RingBuffer, @@ -324,9 +324,7 @@ impl TcpTun { } let before_poll = SmolInstant::now(); - let updated_sockets = iface.poll(before_poll, device, &mut socket_set); - - if updated_sockets { + if let PollResult::SocketStateChanged = iface.poll(before_poll, device, &mut socket_set) { trace!("VirtDevice::poll costed {}", SmolInstant::now() - before_poll); } @@ -357,7 +355,10 @@ impl TcpTun { } // SHUT_WR - if matches!(control.send_state, TcpSocketState::Close) && socket.send_queue() == 0 && control.send_buffer.is_empty() { + if matches!(control.send_state, TcpSocketState::Close) + && socket.send_queue() == 0 + && control.send_buffer.is_empty() + { trace!("closing TCP Write Half, {:?}", socket.state()); // Close the socket. Set to FIN state diff --git a/crates/shadowsocks-service/src/local/tun/virt_device.rs b/crates/shadowsocks-service/src/local/tun/virt_device.rs index f8e97e73409e..02bc0b366653 100644 --- a/crates/shadowsocks-service/src/local/tun/virt_device.rs +++ b/crates/shadowsocks-service/src/local/tun/virt_device.rs @@ -86,11 +86,11 @@ pub struct VirtRxToken<'a> { } impl phy::RxToken for VirtRxToken<'_> { - fn consume(mut self, f: F) -> R + fn consume(self, f: F) -> R where - F: FnOnce(&mut [u8]) -> R, + F: FnOnce(&[u8]) -> R, { - f(&mut self.buffer[..]) + f(&self.buffer) } }