Possible stream shutdown improvement

This commit is contained in:
Mike Dilger 2024-07-13 11:13:46 +12:00
parent 633bb82899
commit 37b1b3a0f3

View File

@ -8,6 +8,7 @@ use std::fs::OpenOptions;
use std::io::Read;
use std::sync::atomic::Ordering;
use std::time::Duration;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpListener;
use tokio::signal::unix::{signal, SignalKind};
@ -86,14 +87,12 @@ async fn main() -> Result<(), Error> {
// Accepts network connections and spawn a task to serve each one
v = listener.accept() => {
let (tcp_stream, hashed_peer) = {
let (mut tcp_stream, hashed_peer) = {
let (tcp_stream, peer_addr) = v?;
let hashed_peer = HashedPeer::new(peer_addr);
(tcp_stream, hashed_peer)
};
let counting_stream = CountingStream(tcp_stream);
// Possibly IP block
if GLOBALS.config.read().enable_ip_blocking {
let ip_data = chorus::get_ip_data(GLOBALS.store.get().unwrap(), hashed_peer.ip())?;
@ -102,10 +101,13 @@ async fn main() -> Result<(), Error> {
"{}: Blocking reconnection until {}",
hashed_peer.ip(),
ip_data.ban_until);
let _ = tcp_stream.shutdown().await;
continue;
}
}
let counting_stream = CountingStream(tcp_stream);
let maybe_tls_acceptor_clone = maybe_tls_acceptor.clone();
tokio::spawn(async move {
match maybe_tls_acceptor_clone {