diff options
author | open-trade <[email protected]> | 2020-03-12 22:06:09 +0800 |
---|---|---|
committer | open-trade <[email protected]> | 2020-03-12 22:06:09 +0800 |
commit | e1e4c9a9652caf4ab0aa643ea80db2cc70854a2b (patch) | |
tree | cbd343f64fdb2d701ac3a590cd9449df03983aab /src | |
parent | db89aaa5c6161b290a22f7e6d04a1323fb3d081d (diff) | |
download | rustdesk-server-e1e4c9a9652caf4ab0aa643ea80db2cc70854a2b.tar.gz rustdesk-server-e1e4c9a9652caf4ab0aa643ea80db2cc70854a2b.zip |
refactored
Diffstat (limited to 'src')
-rw-r--r-- | src/rendezvous_server.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index 9a47305..c1c9467 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -1,6 +1,6 @@ use hbb_common::{ - bytes::BytesMut, log, protobuf::parse_from_bytes, rendezvous_proto::*, udp::FramedSocket, tcp::new_listener, - AddrMangle, ResultType, + allow_err, bytes::BytesMut, log, protobuf::parse_from_bytes, rendezvous_proto::*, + tcp::new_listener, tokio, udp::FramedSocket, AddrMangle, ResultType, }; use std::{collections::HashMap, net::SocketAddr}; @@ -20,19 +20,19 @@ impl RendezvousServer { let mut rs = Self { peer_map: PeerMap::new(), }; - // used to test if udp/tcp share the same NAT port, yes in my test. + // tcp listener used to test if udp/tcp share the same NAT port, yes in my test. // also be used to help client to get local ip. - let addr = addr.to_string(); - hbb_common::tokio::spawn(async { - let mut l = new_listener(addr, true).await.unwrap(); - while let Ok((_, addr)) = l.accept().await { - log::debug!("Tcp connection from {:?}", addr); + let mut listener = new_listener(addr, true).await.unwrap(); + loop { + tokio::select! { + Some(Ok((bytes, addr))) = socket.next() => { + allow_err!(rs.handle_msg(&bytes, addr, &mut socket).await); + } + Ok((_, addr)) = listener.accept() => { + log::debug!("Tcp connection from {:?}", addr); + } } - }); - while let Some(Ok((bytes, addr))) = socket.next().await { - rs.handle_msg(&bytes, addr, &mut socket).await?; } - Ok(()) } pub async fn handle_msg( |