diff --git a/src/tunnel/tcp.rs b/src/tunnel/tcp.rs index 4633e78..e9644b9 100644 --- a/src/tunnel/tcp.rs +++ b/src/tunnel/tcp.rs @@ -123,13 +123,28 @@ async fn handle_tcp_proxy_connection( } Event::RemoteData(e_vp, data) if e_vp == virtual_port => { // Have remote data to send to the local client - let size = data.len(); - match socket.write(&data).await { - Ok(size) => debug!("[{}] Sent {} bytes to local client", virtual_port, size), - Err(e) => { - error!("[{}] Failed to send {} bytes to local client: {:?}", virtual_port, size, e); + if let Err(e) = socket.writable().await { + error!("[{}] Failed to check if writable: {:?}", virtual_port, e); + } + let expected = data.len(); + let mut sent = 0; + loop { + if sent >= expected { break; } + match socket.write(&data[sent..expected]).await { + Ok(written) => { + debug!("[{}] Sent {} (expected {}) bytes to local client", virtual_port, written, expected); + sent += written; + if sent < expected { + debug!("[{}] Will try to resend remaining {} bytes to local client", virtual_port, (expected - written)); + } + }, + Err(e) => { + error!("[{}] Failed to send {} bytes to local client: {:?}", virtual_port, expected, e); + break; + } + } } } _ => {} diff --git a/src/virtual_iface/tcp.rs b/src/virtual_iface/tcp.rs index 3005c3c..28eacac 100644 --- a/src/virtual_iface/tcp.rs +++ b/src/virtual_iface/tcp.rs @@ -164,6 +164,7 @@ impl VirtualInterfacePoll for TcpVirtualInterface { if client_socket.can_recv() { match client_socket.recv(|buffer| (buffer.len(), buffer.to_vec())) { Ok(data) => { + debug!("[{}] Received {} bytes from virtual server", virtual_port, data.len()); if !data.is_empty() { endpoint.send(Event::RemoteData(*virtual_port, data)); }