Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions crates/shadowsocks-service/src/local/tun/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
collections::HashMap,
future::Future,
io::{self, ErrorKind},
mem,
net::{IpAddr, SocketAddr},
Expand Down Expand Up @@ -113,12 +114,12 @@ impl Drop for TcpConnection {
}

impl TcpConnection {
async fn new(
fn new(
socket: TcpSocket<'static>,
socket_creation_tx: &mpsc::UnboundedSender<TcpSocketCreation>,
manager_notify: Arc<ManagerNotify>,
tcp_opts: &TcpSocketOpts,
) -> TcpConnection {
) -> impl Future<Output = TcpConnection> {
let send_buffer_size = tcp_opts.send_buffer_size.unwrap_or(DEFAULT_TCP_SEND_BUFFER_SIZE);
let recv_buffer_size = tcp_opts.recv_buffer_size.unwrap_or(DEFAULT_TCP_RECV_BUFFER_SIZE);

Expand All @@ -136,11 +137,13 @@ impl TcpConnection {
socket,
socket_created_tx: tx,
});
// waiting socket add to SocketSet
let _ = rx.await;
TcpConnection {
control,
manager_notify,
async move {
// waiting socket add to SocketSet
let _ = rx.await;
TcpConnection {
control,
manager_notify,
}
}
}
}
Expand Down Expand Up @@ -524,13 +527,13 @@ impl TcpTun {
&self.manager_socket_creation_tx,
self.manager_notify.clone(),
&accept_opts.tcp,
)
.await;
);

// establish a tunnel
let context = self.context.clone();
let balancer = self.balancer.clone();
tokio::spawn(async move {
let connection = connection.await;
if let Err(err) = handle_redir_client(context, balancer, connection, src_addr, dst_addr).await {
error!("TCP tunnel failure, {} <-> {}, error: {}", src_addr, dst_addr, err);
}
Expand Down