summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-08-28 15:02:14 +0200
committermetamuffin <metamuffin@disroot.org>2023-08-28 15:02:14 +0200
commit186bf476aeab0ff0838d1ae26a9dbcb2e40a8eb5 (patch)
tree384ed6e8faaacd77b1a5f4f11a251ee228f1e927 /src/main.rs
parent2bc557bbddb01b535dd8512fe3aadb0d4091a42d (diff)
downloadgnix-186bf476aeab0ff0838d1ae26a9dbcb2e40a8eb5.tar
gnix-186bf476aeab0ff0838d1ae26a9dbcb2e40a8eb5.tar.bz2
gnix-186bf476aeab0ff0838d1ae26a9dbcb2e40a8eb5.tar.zst
what i invented here already existed: semaphore
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 5230434..4d14bec 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,7 +5,6 @@ pub mod config;
pub mod error;
pub mod files;
pub mod helper;
-pub mod limiter;
pub mod proxy;
use crate::{
@@ -26,16 +25,15 @@ use hyper::{
service::service_fn,
Request, Response, StatusCode,
};
-use limiter::Limiter;
use log::{debug, error, info, warn};
use std::{fs::File, io::BufReader, net::SocketAddr, path::Path, process::exit, sync::Arc};
-use tokio::{net::TcpListener, signal::ctrl_c};
+use tokio::{net::TcpListener, signal::ctrl_c, sync::Semaphore};
use tokio_rustls::TlsAcceptor;
pub struct State {
pub config: Config,
- pub l_incoming: Limiter,
- pub l_outgoing: Limiter,
+ pub l_incoming: Semaphore,
+ pub l_outgoing: Semaphore,
}
#[tokio::main]
@@ -54,8 +52,8 @@ async fn main() -> anyhow::Result<()> {
}
};
let state = Arc::new(State {
- l_incoming: Limiter::new(config.limits.max_incoming_connections),
- l_outgoing: Limiter::new(config.limits.max_outgoing_connections),
+ l_incoming: Semaphore::new(config.limits.max_incoming_connections),
+ l_outgoing: Semaphore::new(config.limits.max_outgoing_connections),
config,
});
@@ -153,7 +151,7 @@ pub async fn serve_stream<T: Unpin + Send + 'static + hyper::rt::Read + hyper::r
stream: T,
addr: SocketAddr,
) {
- if let Some(_limit_guard) = state.l_incoming.obtain() {
+ if let Ok(_semaphore) = state.l_incoming.try_acquire() {
let conn = http1::Builder::new()
.serve_connection(
stream,