Просмотр исходного кода

net: handler listener failuer and don't let the acceptor stop

ghassmo 4 лет назад
Родитель
Сommit
2558380865
2 измененных файлов с 12 добавлено и 6 удалено
  1. 9 3
      src/net/acceptor.rs
  2. 3 3
      src/net/transport/tcp.rs

+ 9 - 3
src/net/acceptor.rs

@@ -140,9 +140,15 @@ impl Acceptor {
     /// Run the accept loop.
     async fn run_accept_loop(self: Arc<Self>, listener: Box<dyn TransportListener>) -> Result<()> {
         loop {
-            let (stream, peer_addr) = listener.next().await?;
-            let channel = Channel::new(stream, peer_addr).await;
-            self.channel_subscriber.notify(Ok(channel)).await;
+            match listener.next().await {
+                Ok((stream, url)) => {
+                    let channel = Channel::new(stream, url).await;
+                    self.channel_subscriber.notify(Ok(channel)).await;
+                }
+                Err(e) => {
+                    error!("Error listening for new connection: {}", e);
+                }
+            }
         }
     }
 

+ 3 - 3
src/net/transport/tcp.rs

@@ -42,13 +42,13 @@ impl TransportListener for (TlsAcceptor, TcpListener) {
 
         let stream = self.0.accept(stream).await;
 
+        let url = socket_addr_to_url(peer_addr, "tcp+tls")?;
+
         if let Err(err) = stream {
-            error!("Error wraping the connection with tls: {}", err);
+            error!("Error wraping the connection {} with tls: {}", url, err);
             return Err(Error::AcceptTlsConnectionFailed(self.1.local_addr()?.to_string()))
         }
 
-        let url = socket_addr_to_url(peer_addr, "tcp+tls")?;
-
         Ok((Box::new(TlsStream::Server(stream?)), url))
     }
 }