From c8e44bb740baea0bc0f5d2bd5be587e049c26f48 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sat, 17 Jul 2021 20:07:26 +0000 Subject: [PATCH] :bug: bug: P2 no longer exits when P1 closes the connection --- .../quic_demo/src/bin/quic_demo_client.rs | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/prototypes/quic_demo/src/bin/quic_demo_client.rs b/prototypes/quic_demo/src/bin/quic_demo_client.rs index 79fafcd..275cc6b 100644 --- a/prototypes/quic_demo/src/bin/quic_demo_client.rs +++ b/prototypes/quic_demo/src/bin/quic_demo_client.rs @@ -27,35 +27,42 @@ async fn main () -> anyhow::Result <()> { let mut resp_buf = [0u8, 0, 0, 0]; recv.read_exact (&mut resp_buf).await?; - debug! ("Waiting for local TCP client to connect to us"); - let listener = TcpListener::bind ("127.0.0.1:30381").await?; - let (tcp_socket, _) = listener.accept ().await?; - let (local_recv, local_send) = tcp_socket.into_split (); - debug! ("Connecting to end server"); + debug! ("Accepting local TCP connections"); - let (mut relay_send, mut relay_recv) = connection.open_bi ().await?; - - let req_buf = [1, 43, 0, 0, 1, 0, 0, 0]; - relay_send.write_all (&req_buf).await?; - - let mut resp_buf = [0; 8]; - relay_recv.read_exact (&mut resp_buf).await?; - - debug! ("Relaying bytes..."); - - let ptth_conn = PtthNewConnection { - local_send, - local_recv, - relay_send, - relay_recv, - }.build (); - - ptth_conn.uplink_task.await??; - ptth_conn.downlink_task.await??; - - Ok (()) + loop { + let (tcp_socket, _) = listener.accept ().await?; + let connection = connection.clone (); + + tokio::spawn (async move { + let (local_recv, local_send) = tcp_socket.into_split (); + + debug! ("Connecting to end server"); + + let (mut relay_send, mut relay_recv) = connection.open_bi ().await?; + + let req_buf = [1, 43, 0, 0, 1, 0, 0, 0]; + relay_send.write_all (&req_buf).await?; + + let mut resp_buf = [0; 8]; + relay_recv.read_exact (&mut resp_buf).await?; + + debug! ("Relaying bytes..."); + + let ptth_conn = PtthNewConnection { + local_send, + local_recv, + relay_send, + relay_recv, + }.build (); + + ptth_conn.uplink_task.await??; + ptth_conn.downlink_task.await??; + + Ok::<_, anyhow::Error> (()) + }); + } } struct PtthNewConnection {