Skip to content

Commit 5de6c5e

Browse files
committed
Close proxy when connection is closed
1 parent 58cef55 commit 5de6c5e

File tree

1 file changed

+20
-4
lines changed
  • fortanix-vme/fortanix-vme-runner/src

1 file changed

+20
-4
lines changed

fortanix-vme/fortanix-vme-runner/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,29 @@ impl Server {
297297

298298
if let Ok(_num) = select(None, Some(&mut read_set), None, None, None) {
299299
if read_set.contains(remote.0.as_raw_fd()) {
300-
if let Err(_) = Self::transfer_data(remote.0, remote.1, proxy.0, proxy.1) {
301-
break;
300+
match Self::transfer_data(remote.0, remote.1, proxy.0, proxy.1) {
301+
Ok(0) => {
302+
// According to the `Read` threat documentation, reading 0 bytes
303+
// indicates that the connection has been shutdown correctly. So we
304+
// close the proxy service
305+
// https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read
306+
break
307+
},
308+
Ok(_) => (),
309+
Err(e) => {
310+
eprintln!("transfer from remote failed: {:?}", e);
311+
break;
312+
}
302313
}
303314
}
304315
if read_set.contains(proxy.0.as_raw_fd()) {
305-
if let Err(_) = Self::transfer_data(proxy.0, proxy.1, remote.0, remote.1) {
306-
break;
316+
match Self::transfer_data(proxy.0, proxy.1, remote.0, remote.1) {
317+
Ok(0) => break,
318+
Ok(_) => (),
319+
Err(e) => {
320+
eprintln!("transfer from proxy failed: {:?}", e);
321+
break;
322+
}
307323
}
308324
}
309325
}

0 commit comments

Comments
 (0)