Crate xcore

Source
Expand description

xcore,is a simple epoll based TCP Server framework.

§Usage

pub struct Handler {
   map: BTreeSet<i32>,
}
impl Handler {
   pub fn add_user(&mut self, fd: i32) {
       self.map.insert(fd);
   }
}
// handler executed in different thread
pub fn handler(fd: i32,
              socket: &mut TcpStream,
              commander: Sender<Ctrl>,
              handle: Arc<RwLock<Handler>>){
    let wirte_handle = handle.write().unwrap();
    write_handle.add_user(fd);
}

fn main() {
    let h = Handler {
       map: BTreeSet::new(),
   };

    let listen: Listener = Listener::new("127.0.0.1:6666");
    let worker: Executor = Executor::new(2000,4, handler,h);

    loop {
        let v = listen.get_stream();
        match v {
            Some(v) => {
                worker.add(v);
            }
            None => {}
        }
    }
}

Structs§

  • Executor to manage socket poll and execute response to handle message
  • Async TCP listener wrapper

Enums§