mirror of
https://github.com/mikedilger/chorus.git
synced 2026-05-03 06:51:42 +00:00
Remove http server from globals, create one each time (cheap)
This commit is contained in:
parent
9759fe6e28
commit
fde63df92b
@ -124,18 +124,8 @@ async fn main() -> Result<(), Error> {
|
||||
},
|
||||
None => Box::new(counting_stream)
|
||||
};
|
||||
if let Err(e) = chorus::serve(stream, hashed_peer).await {
|
||||
log::error!(
|
||||
target: "Client",
|
||||
"{}: {}", hashed_peer, e
|
||||
);
|
||||
}
|
||||
chorus::serve(stream, hashed_peer).await;
|
||||
});
|
||||
|
||||
//Err(e) => log::error!(
|
||||
//target: "Client",
|
||||
//"{}: {}", hashed_peer, e
|
||||
//),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::config::Config;
|
||||
use crate::ip::HashedIp;
|
||||
use dashmap::DashMap;
|
||||
use hyper::server::conn::Http;
|
||||
use lazy_static::lazy_static;
|
||||
use parking_lot::RwLock;
|
||||
use pocket_db::Store;
|
||||
@ -17,7 +16,6 @@ pub struct Globals {
|
||||
pub bytes_outbound: AtomicU64,
|
||||
pub config: RwLock<Config>,
|
||||
pub store: OnceLock<Store>,
|
||||
pub http_server: Http,
|
||||
pub rid: OnceLock<String>,
|
||||
|
||||
/// This is a broadcast channel where new incoming events are advertised by their offset.
|
||||
@ -33,10 +31,6 @@ pub struct Globals {
|
||||
|
||||
lazy_static! {
|
||||
pub static ref GLOBALS: Globals = {
|
||||
let mut http_server = hyper::server::conn::Http::new();
|
||||
http_server.http1_only(true);
|
||||
http_server.http1_keep_alive(true);
|
||||
|
||||
let (new_events, _) = tokio::sync::broadcast::channel(512);
|
||||
let (shutting_down, _) = tokio::sync::watch::channel(false);
|
||||
|
||||
@ -46,7 +40,6 @@ lazy_static! {
|
||||
bytes_outbound: AtomicU64::new(0),
|
||||
config: RwLock::new(Default::default()),
|
||||
store: OnceLock::new(),
|
||||
http_server,
|
||||
rid: OnceLock::new(),
|
||||
new_events,
|
||||
num_connections: AtomicUsize::new(0),
|
||||
|
||||
22
src/lib.rs
22
src/lib.rs
@ -48,16 +48,27 @@ impl FullStream for CountingStream<TcpStream> {}
|
||||
impl FullStream for TlsStream<CountingStream<TcpStream>> {}
|
||||
|
||||
/// Serve a single network connection
|
||||
pub async fn serve(stream: Box<dyn FullStream>, peer: HashedPeer) -> Result<(), Error> {
|
||||
pub async fn serve(stream: Box<dyn FullStream>, peer: HashedPeer) {
|
||||
// Serve the network stream with our http server and our HttpService
|
||||
let service = HttpService { peer };
|
||||
|
||||
let connection = GLOBALS
|
||||
.http_server
|
||||
let mut http_server = hyper::server::conn::Http::new();
|
||||
http_server.http1_only(true);
|
||||
http_server.http1_keep_alive(true);
|
||||
let connection = http_server
|
||||
.serve_connection(stream, service)
|
||||
.with_upgrades();
|
||||
|
||||
tokio::spawn(async move {
|
||||
/* hyper 1
|
||||
let mut http1builder = http1::Builder::new();
|
||||
http1builder.half_close(true);
|
||||
http1builder.keep_alive(true);
|
||||
http1builder.header_read_timeout(Duration::from_secs(5));
|
||||
let connection = http1builder
|
||||
.serve_connection(stream, service)
|
||||
.with_upgrades();
|
||||
*/
|
||||
|
||||
// If our service exits with an error, log the error
|
||||
if let Err(he) = connection.await {
|
||||
if let Some(src) = he.source() {
|
||||
@ -73,9 +84,6 @@ pub async fn serve(stream: Box<dyn FullStream>, peer: HashedPeer) -> Result<(),
|
||||
log::error!(target: "Client", "{}: {}", peer, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This is our per-connection HTTP service
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user