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:
parent
137309cc4e
commit
a5e3be4992
|
@ -170,19 +170,31 @@ async fn run() -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
type ClientStreamResult =
|
||||
Result<std::pin::Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>, Error>;
|
||||
const MAX_PENDING_ACCEPTS: usize = 1024;
|
||||
|
||||
fn accept_connections(
|
||||
listener: tokio::net::TcpListener,
|
||||
acceptor: Arc<openssl::ssl::SslAcceptor>,
|
||||
debug: bool,
|
||||
) -> tokio::sync::mpsc::Receiver<Result<std::pin::Pin<Box<tokio_openssl::SslStream<tokio::net::TcpStream>>>, Error>> {
|
||||
|
||||
const MAX_PENDING_ACCEPTS: usize = 1024;
|
||||
) -> tokio::sync::mpsc::Receiver<ClientStreamResult> {
|
||||
|
||||
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(());
|
||||
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
match listener.accept().await {
|
||||
Err(err) => {
|
||||
|
@ -246,9 +258,6 @@ fn accept_connections(
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
receiver
|
||||
}
|
||||
|
||||
fn start_stat_generator() {
|
||||
|
|
Loading…
Reference in New Issue