|
@@ -1,12 +1,9 @@
|
|
use bytes::Bytes;
|
|
use bytes::Bytes;
|
|
use sib::network::http::{
|
|
use sib::network::http::{
|
|
- h1::{H1Service, H1ServiceFactory},
|
|
|
|
- util::Status,
|
|
|
|
- session::Session,
|
|
|
|
|
|
+ server::HFactory, session::{HService, Session}, util::Status
|
|
};
|
|
};
|
|
use std::{
|
|
use std::{
|
|
- fs,
|
|
|
|
- io::{Read, Write},
|
|
|
|
|
|
+ fs
|
|
};
|
|
};
|
|
|
|
|
|
#[global_allocator]
|
|
#[global_allocator]
|
|
@@ -25,12 +22,10 @@ impl Default for JsonMessage<'_> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-struct H1Server<T>(pub T);
|
|
|
|
|
|
+struct Server;
|
|
|
|
|
|
-struct HService;
|
|
|
|
-
|
|
|
|
-impl H1Service for HService {
|
|
|
|
- fn call<S: Read + Write>(&mut self, session: &mut Session<S>) -> std::io::Result<()> {
|
|
|
|
|
|
+impl HService for Server {
|
|
|
|
+ fn call<S: Session>(&mut self, session: &mut S) -> std::io::Result<()> {
|
|
if session.req_path() == Some("/json") {
|
|
if session.req_path() == Some("/json") {
|
|
// Respond with JSON
|
|
// Respond with JSON
|
|
let json = serde_json::to_vec(&JsonMessage::default())?;
|
|
let json = serde_json::to_vec(&JsonMessage::default())?;
|
|
@@ -52,11 +47,11 @@ impl H1Service for HService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl H1ServiceFactory for H1Server<HService> {
|
|
|
|
- type Service = HService;
|
|
|
|
|
|
+impl HFactory for Server{
|
|
|
|
+ type Service = Server;
|
|
|
|
|
|
- fn service(&self, _id: usize) -> HService {
|
|
|
|
- HService
|
|
|
|
|
|
+ fn service(&self, _id: usize) -> Server {
|
|
|
|
+ Server
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -65,6 +60,8 @@ fn main() {
|
|
let cpus = num_cpus::get();
|
|
let cpus = num_cpus::get();
|
|
println!("CPU cores: {cpus}");
|
|
println!("CPU cores: {cpus}");
|
|
|
|
|
|
|
|
+ sib::set_num_workers(cpus);
|
|
|
|
+
|
|
// Print total RAM in MB
|
|
// Print total RAM in MB
|
|
if let Ok(meminfo) = fs::read_to_string("/proc/meminfo") {
|
|
if let Ok(meminfo) = fs::read_to_string("/proc/meminfo") {
|
|
for line in meminfo.lines() {
|
|
for line in meminfo.lines() {
|
|
@@ -89,8 +86,8 @@ fn main() {
|
|
let handle = std::thread::spawn(move || {
|
|
let handle = std::thread::spawn(move || {
|
|
let id = std::thread::current().id();
|
|
let id = std::thread::current().id();
|
|
println!("Listening {addr} on thread: {id:?}");
|
|
println!("Listening {addr} on thread: {id:?}");
|
|
- H1Server(HService)
|
|
|
|
- .start(addr, cpus, 0)
|
|
|
|
|
|
+ Server
|
|
|
|
+ .start_h1(addr, 0)
|
|
.unwrap_or_else(|_| panic!("h1 server failed to start for thread {id:?}"))
|
|
.unwrap_or_else(|_| panic!("h1 server failed to start for thread {id:?}"))
|
|
.join()
|
|
.join()
|
|
.unwrap_or_else(|_| panic!("h1 server failed to joining thread {id:?}"));
|
|
.unwrap_or_else(|_| panic!("h1 server failed to joining thread {id:?}"));
|