diff --git a/src/proxy/proxy_h3.rs b/src/proxy/proxy_h3.rs index 8db08a3..4be9b00 100644 --- a/src/proxy/proxy_h3.rs +++ b/src/proxy/proxy_h3.rs @@ -9,7 +9,23 @@ impl Proxy where T: Connect + Clone + Sync + Send + 'static, { - pub async fn client_serve_h3(self, conn: quinn::Connecting) -> Result<()> { + pub async fn client_serve_h3(self, conn: quinn::Connecting) { + let clients_count = self.globals.clients_count.clone(); + if clients_count.increment() > self.globals.max_clients { + clients_count.decrement(); + return; + } + let fut = self.clone().handle_connection_h3(conn); + self.globals.runtime_handle.spawn(async move { + if let Err(e) = fut.await { + warn!("QUIC or HTTP/3 connection failed: {}", e) + } + clients_count.decrement(); + debug!("Client #: {}", clients_count.current()); + }); + } + + pub async fn handle_connection_h3(self, conn: quinn::Connecting) -> Result<()> { let client_addr = conn.remote_address(); match conn.await { diff --git a/src/proxy/proxy_tls.rs b/src/proxy/proxy_tls.rs index b3471f7..61ee792 100644 --- a/src/proxy/proxy_tls.rs +++ b/src/proxy/proxy_tls.rs @@ -147,20 +147,7 @@ where let peekable_incoming = std::pin::Pin::new(&mut p); if let Some(conn) = peekable_incoming.get_mut().next().await { if success { - // TODO: client数の管理 - let clients_count = self.globals.clients_count.clone(); - if clients_count.increment() > self.globals.max_clients { - clients_count.decrement(); - continue; - } - let fut = self.clone().client_serve_h3(conn); - self.globals.runtime_handle.spawn(async move { - if let Err(e) = fut.await { - warn!("QUIC or HTTP/3 connection failed: {}", e) - } - clients_count.decrement(); - debug!("Client #: {}", clients_count.current()); - }); + self.clone().client_serve_h3(conn).await; } } else { break;