#sockets #server #listen #selector #default #syscalls #avoiding

nightly socket_server

socket 写事件轮询注册避免系统调用

8 个重大版本更新

新功能 0.12.0 2024年8月6日
0.10.0 2024年8月5日
0.1.0 2024年7月18日

#1 in #avoiding

Download history 98/week @ 2024-07-16 6/week @ 2024-07-23 370/week @ 2024-07-30

每月 475 次下载

MIT 许可证

61KB
1.5K SLoC

示例

use std::time::Duration;

use qcell::LCellOwner;
use socket_server::{
    selector::listen,
    socket::{ServerSocketListener, Socket},
};

fn main() {
    LCellOwner::scope(|mut owner| listen(&mut owner, GameServer, "[::]:0"));
}

pub struct GameServer;
#[derive(Default)]
pub struct Player {}

impl<'id> ServerSocketListener<'id> for GameServer {
    const MAX_CONNECTIONS: usize = 10;
    const READ_BUFFFER_LEN: usize = 100;
    const WRITE_BUFFER_LEN: usize = 100;
    const TICK: Duration = Duration::from_millis(50);
    type Connection = Player;

    fn tick(&mut self, owner: &mut LCellOwner<'id>) {
        todo!()
    }

    fn accept(&mut self, owner: &mut LCellOwner<'id>, connection: &mut Socket<'id, '_, Self>) {
        todo!()
    }

    fn read(&mut self, owner: &mut LCellOwner<'id>, connection: &mut Socket<'id, '_, Self>) {
        todo!()
    }

    fn flush(&mut self, owner: &mut LCellOwner<'id>, connection: &mut Socket<'id, '_, Self>) {
        todo!()
    }

    fn close(&mut self, owner: &mut LCellOwner<'id>, connection: &mut Socket<'id, '_, Self>) {
        todo!()
    }
}

依赖项

~0.8–8.5MB
~65K SLoC