mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 06:38:32 -04:00
parent
def5f22d3c
commit
11f86c49d6
2 changed files with 21 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue