author | sheepluva |
Sun, 07 Jan 2018 19:01:06 +0100 | |
changeset 12886 | a089326f0e16 |
parent 12853 | a9d105dc5c95 |
child 13119 | 1e39b8749072 |
permissions | -rw-r--r-- |
12125 | 1 |
extern crate rand; |
2 |
extern crate mio; |
|
12126 | 3 |
extern crate slab; |
12127 | 4 |
extern crate netbuf; |
12133 | 5 |
#[macro_use] |
6 |
extern crate nom; |
|
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
7 |
#[macro_use] |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
8 |
extern crate log; |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
9 |
extern crate env_logger; |
12125 | 10 |
|
12126 | 11 |
//use std::io::*; |
12125 | 12 |
//use rand::Rng; |
13 |
//use std::cmp::Ordering; |
|
12853 | 14 |
use mio::net::*; |
12125 | 15 |
use mio::*; |
16 |
||
17 |
mod utils; |
|
12126 | 18 |
mod server; |
12129 | 19 |
mod protocol; |
12125 | 20 |
|
21 |
fn main() { |
|
12137
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
22 |
env_logger::init().unwrap(); |
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
23 |
|
193dfdcb0620
- Use logging facilities instead of plain println!
unc0rr
parents:
12133
diff
changeset
|
24 |
info!("Hedgewars game server, protocol {}", utils::PROTOCOL_VERSION); |
12125 | 25 |
|
26 |
let address = "0.0.0.0:46631".parse().unwrap(); |
|
12126 | 27 |
let listener = TcpListener::bind(&address).unwrap(); |
12128 | 28 |
let mut server = server::server::HWServer::new(listener, 1024, 512); |
12125 | 29 |
|
30 |
let poll = Poll::new().unwrap(); |
|
12126 | 31 |
server.register(&poll).unwrap(); |
12125 | 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() { |
|
12853 | 39 |
if event.readiness() & Ready::readable() == Ready::readable() { |
12127 | 40 |
match event.token() { |
41 |
utils::SERVER => server.accept(&poll).unwrap(), |
|
12852 | 42 |
Token(tok) => server.client_readable(&poll, tok).unwrap(), |
12127 | 43 |
} |
44 |
} |
|
12853 | 45 |
if event.readiness() & Ready::writable() == Ready::writable() { |
12127 | 46 |
match event.token() { |
47 |
utils::SERVER => unreachable!(), |
|
12852 | 48 |
Token(tok) => server.client_writable(&poll, tok).unwrap(), |
12127 | 49 |
} |
12125 | 50 |
} |
12853 | 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 |
// } |
|
12125 | 57 |
} |
58 |
} |
|
59 |
} |