Merge pull request #32 from aramperes/22-fix

This commit is contained in:
Aram 🍐 2022-01-09 22:57:32 -05:00 committed by GitHub
commit e99fe6b8fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 5 deletions

View file

@ -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;
}
}
} }
} }
_ => {} _ => {}

View file

@ -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));
} }