author | Wuzzy <Wuzzy2@mail.ru> |
Thu, 08 Mar 2018 00:46:00 +0100 | |
changeset 13105 | 61076bb26cb3 |
parent 12858 | a9d105dc5c95 |
child 13124 | 1e39b8749072 |
permissions | -rw-r--r-- |
12130 | 1 |
extern crate rand; |
2 |
extern crate mio; |
|
12131 | 3 |
extern crate slab; |
12132 | 4 |
extern crate netbuf; |
12138 | 5 |
#[macro_use] |
6 |
extern crate nom; |
|
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
7 |
#[macro_use] |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
8 |
extern crate log; |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
9 |
extern crate env_logger; |
12130 | 10 |
|
12131 | 11 |
//use std::io::*; |
12130 | 12 |
//use rand::Rng; |
13 |
//use std::cmp::Ordering; |
|
12858 | 14 |
use mio::net::*; |
12130 | 15 |
use mio::*; |
16 |
||
17 |
mod utils; |
|
12131 | 18 |
mod server; |
12134 | 19 |
mod protocol; |
12130 | 20 |
|
21 |
fn main() { |
|
12142
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
22 |
env_logger::init().unwrap(); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
23 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12138
diff
changeset
|
24 |
info!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION); |
12130 | 25 |
|
26 |
let address = "0.0.0.0:46631".parse().unwrap(); |
|
12131 | 27 |
let listener = TcpListener::bind(&address).unwrap(); |
12133 | 28 |
let mut server = server::server::HWServer::new(listener, 1024, 512); |
12130 | 29 |
|
30 |
let poll = Poll::new().unwrap(); |
|
12131 | 31 |
server.register(&poll).unwrap(); |
12130 | 32 |
|
33 |
let mut events = Events::with_capacity(1024); |
|
34 |
||
35 |
loop { |
|
36 |
poll.poll(&mut events, None).unwrap(); |
|
37 |
||
38 |
for event in events.iter() { |
|
12858 | 39 |
if event.readiness() & Ready::readable() == Ready::readable() { |
12132 | 40 |
match event.token() { |
41 |
utils::SERVER => server.accept(&poll).unwrap(), |
|
12857 | 42 |
Token(tok) => server.client_readable(&poll, tok).unwrap(), |
12132 | 43 |
} |
44 |
} |
|
12858 | 45 |
if event.readiness() & Ready::writable() == Ready::writable() { |
12132 | 46 |
match event.token() { |
47 |
utils::SERVER => unreachable!(), |
|
12857 | 48 |
Token(tok) => server.client_writable(&poll, tok).unwrap(), |
12132 | 49 |
} |
12130 | 50 |
} |
12858 | 51 |
// if event.kind().is_hup() || event.kind().is_error() { |
52 |
// match event.token() { |
|
53 |
// utils::SERVER => unreachable!(), |
|
54 |
// Token(tok) => server.client_error(&poll, tok).unwrap(), |
|
55 |
// } |
|
56 |
// } |
|
12130 | 57 |
} |
58 |
} |
|
59 |
} |