gameServer2/src/main.rs
changeset 12853 a9d105dc5c95
parent 12852 bd35cb2302b3
child 13119 1e39b8749072
equal deleted inserted replaced
12852:bd35cb2302b3 12853:a9d105dc5c95
     9 extern crate env_logger;
     9 extern crate env_logger;
    10 
    10 
    11 //use std::io::*;
    11 //use std::io::*;
    12 //use rand::Rng;
    12 //use rand::Rng;
    13 //use std::cmp::Ordering;
    13 //use std::cmp::Ordering;
    14 use mio::tcp::*;
    14 use mio::net::*;
    15 use mio::*;
    15 use mio::*;
    16 
    16 
    17 mod utils;
    17 mod utils;
    18 mod server;
    18 mod server;
    19 mod protocol;
    19 mod protocol;
    34 
    34 
    35     loop {
    35     loop {
    36         poll.poll(&mut events, None).unwrap();
    36         poll.poll(&mut events, None).unwrap();
    37 
    37 
    38         for event in events.iter() {
    38         for event in events.iter() {
    39             if event.kind().is_readable() {
    39             if event.readiness() & Ready::readable() == Ready::readable() {
    40                 match event.token() {
    40                 match event.token() {
    41                     utils::SERVER => server.accept(&poll).unwrap(),
    41                     utils::SERVER => server.accept(&poll).unwrap(),
    42                     Token(tok) => server.client_readable(&poll, tok).unwrap(),
    42                     Token(tok) => server.client_readable(&poll, tok).unwrap(),
    43                 }
    43                 }
    44             }
    44             }
    45             if event.kind().is_writable() {
    45             if event.readiness() & Ready::writable() == Ready::writable() {
    46                 match event.token() {
    46                 match event.token() {
    47                     utils::SERVER => unreachable!(),
    47                     utils::SERVER => unreachable!(),
    48                     Token(tok) => server.client_writable(&poll, tok).unwrap(),
    48                     Token(tok) => server.client_writable(&poll, tok).unwrap(),
    49                 }
    49                 }
    50             }
    50             }
    51             if event.kind().is_hup() || event.kind().is_error() {
    51 //            if event.kind().is_hup() || event.kind().is_error() {
    52                 match event.token() {
    52 //                match event.token() {
    53                     utils::SERVER => unreachable!(),
    53 //                    utils::SERVER => unreachable!(),
    54                     Token(tok) => server.client_error(&poll, tok).unwrap(),
    54 //                    Token(tok) => server.client_error(&poll, tok).unwrap(),
    55                 }
    55 //                }
    56             }
    56 //            }
    57         }
    57         }
    58     }
    58     }
    59 }
    59 }