mirror of
https://github.com/aramperes/onetun.git
synced 2025-09-09 12:38:31 -04:00
Merge pull request #32 from aramperes/22-fix
This commit is contained in:
commit
e99fe6b8fb
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 => {
|
Event::RemoteData(e_vp, data) if e_vp == virtual_port => {
|
||||||
// Have remote data to send to the local client
|
// Have remote data to send to the local client
|
||||||
let size = data.len();
|
if let Err(e) = socket.writable().await {
|
||||||
match socket.write(&data).await {
|
error!("[{}] Failed to check if writable: {:?}", virtual_port, e);
|
||||||
Ok(size) => debug!("[{}] Sent {} bytes to local client", virtual_port, size),
|
}
|
||||||
Err(e) => {
|
let expected = data.len();
|
||||||
error!("[{}] Failed to send {} bytes to local client: {:?}", virtual_port, size, e);
|
let mut sent = 0;
|
||||||
|
loop {
|
||||||
|
if sent >= expected {
|
||||||
break;
|
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() {
|
if client_socket.can_recv() {
|
||||||
match client_socket.recv(|buffer| (buffer.len(), buffer.to_vec())) {
|
match client_socket.recv(|buffer| (buffer.len(), buffer.to_vec())) {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
|
debug!("[{}] Received {} bytes from virtual server", virtual_port, data.len());
|
||||||
if !data.is_empty() {
|
if !data.is_empty() {
|
||||||
endpoint.send(Event::RemoteData(*virtual_port, data));
|
endpoint.send(Event::RemoteData(*virtual_port, data));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue