scale the socket engine: mio epoll reactor for client connections (tens of thousands on a few threads)
This commit is contained in:
parent
1581bc15d2
commit
58596aea66
8 changed files with 379 additions and 40 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -20,7 +20,16 @@ fn main() {
|
|||
.unwrap_or_else(|| "echoircd.conf".to_string());
|
||||
let cfg = Config::load(&path);
|
||||
|
||||
let listener = match TcpListener::bind(&cfg.bind) {
|
||||
// Client plaintext connections run on the mio reactor, so bind a mio listener
|
||||
// (fail fast if the main port is taken).
|
||||
let bind_addr: std::net::SocketAddr = match cfg.bind.parse() {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
eprintln!("echoircd: bad bind address {}: {e}", cfg.bind);
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
let client_listener = match mio::net::TcpListener::bind(bind_addr) {
|
||||
Ok(l) => l,
|
||||
Err(e) => {
|
||||
eprintln!("echoircd: cannot bind {}: {e}", cfg.bind);
|
||||
|
|
@ -101,6 +110,7 @@ fn main() {
|
|||
});
|
||||
}
|
||||
|
||||
socketengine::accept_loop(listener, tx, None, counter, false);
|
||||
// client plaintext connections: one mio reactor thread drives them all
|
||||
thread::spawn(move || socketengine::run_reactor(client_listener, tx, counter));
|
||||
let _ = core.join();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue