proxy: factor out accept_connection

no functional changes, moved code and named the channel's
type for more readability

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2021-05-11 15:53:54 +02:00 committed by Thomas Lamprecht
parent 137309cc4e
commit a5e3be4992
1 changed files with 79 additions and 70 deletions

View File

@ -170,19 +170,31 @@ async fn run() -> Result<(), Error> {
Ok(()) Ok(())
} }
type ClientStreamResult =
Result<std::pin::Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>, Error>;
const MAX_PENDING_ACCEPTS: usize = 1024;
fn accept_connections( fn accept_connections(
listener: tokio::net::TcpListener, listener: tokio::net::TcpListener,
acceptor: Arc<openssl::ssl::SslAcceptor>, acceptor: Arc<openssl::ssl::SslAcceptor>,
debug: bool, debug: bool,
) -> tokio::sync::mpsc::Receiver<Result<std::pin::Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>, Error>> { ) -> tokio::sync::mpsc::Receiver<ClientStreamResult> {
const MAX_PENDING_ACCEPTS: usize = 1024;
let (sender, receiver) = tokio::sync::mpsc::channel(MAX_PENDING_ACCEPTS); let (sender, receiver) = tokio::sync::mpsc::channel(MAX_PENDING_ACCEPTS);
tokio::spawn(accept_connection(listener, acceptor, debug, sender));
receiver
}
async fn accept_connection(
listener: tokio::net::TcpListener,
acceptor: Arc<openssl::ssl::SslAcceptor>,
debug: bool,
sender: tokio::sync::mpsc::Sender<ClientStreamResult>,
) {
let accept_counter = Arc::new(()); let accept_counter = Arc::new(());
tokio::spawn(async move {
loop { loop {
match listener.accept().await { match listener.accept().await {
Err(err) => { Err(err) => {
@ -246,9 +258,6 @@ fn accept_connections(
} }
} }
} }
});
receiver
} }
fn start_stat_generator() { fn start_stat_generator() {