1
1
use bytes:: Bytes ;
2
2
use sib:: network:: http:: {
3
- h1:: { H1Service , H1ServiceFactory } ,
4
- util:: Status ,
5
- session:: Session ,
3
+ server:: HFactory , session:: { HService , Session } , util:: Status
6
4
} ;
7
5
use std:: {
8
- fs,
9
- io:: { Read , Write } ,
6
+ fs
10
7
} ;
11
8
12
9
#[ global_allocator]
@@ -25,12 +22,10 @@ impl Default for JsonMessage<'_> {
25
22
}
26
23
}
27
24
28
- struct H1Server < T > ( pub T ) ;
25
+ struct Server ;
29
26
30
- struct HService ;
31
-
32
- impl H1Service for HService {
33
- fn call < S : Read + Write > ( & mut self , session : & mut Session < S > ) -> std:: io:: Result < ( ) > {
27
+ impl HService for Server {
28
+ fn call < S : Session > ( & mut self , session : & mut S ) -> std:: io:: Result < ( ) > {
34
29
if session. req_path ( ) == Some ( "/json" ) {
35
30
// Respond with JSON
36
31
let json = serde_json:: to_vec ( & JsonMessage :: default ( ) ) ?;
@@ -52,11 +47,11 @@ impl H1Service for HService {
52
47
}
53
48
}
54
49
55
- impl H1ServiceFactory for H1Server < HService > {
56
- type Service = HService ;
50
+ impl HFactory for Server {
51
+ type Service = Server ;
57
52
58
- fn service ( & self , _id : usize ) -> HService {
59
- HService
53
+ fn service ( & self , _id : usize ) -> Server {
54
+ Server
60
55
}
61
56
}
62
57
@@ -65,6 +60,8 @@ fn main() {
65
60
let cpus = num_cpus:: get ( ) ;
66
61
println ! ( "CPU cores: {cpus}" ) ;
67
62
63
+ sib:: set_num_workers ( cpus) ;
64
+
68
65
// Print total RAM in MB
69
66
if let Ok ( meminfo) = fs:: read_to_string ( "/proc/meminfo" ) {
70
67
for line in meminfo. lines ( ) {
@@ -89,8 +86,8 @@ fn main() {
89
86
let handle = std:: thread:: spawn ( move || {
90
87
let id = std:: thread:: current ( ) . id ( ) ;
91
88
println ! ( "Listening {addr} on thread: {id:?}" ) ;
92
- H1Server ( HService )
93
- . start ( addr, cpus , 0 )
89
+ Server
90
+ . start_h1 ( addr, 0 )
94
91
. unwrap_or_else ( |_| panic ! ( "h1 server failed to start for thread {id:?}" ) )
95
92
. join ( )
96
93
. unwrap_or_else ( |_| panic ! ( "h1 server failed to joining thread {id:?}" ) ) ;
0 commit comments