#sockets #server #events #listen #selector #default #qcell

nightly socket_server

socket write event polling registration avoiding syscall

8 breaking releases

0.12.0 Aug 6, 2024
0.10.0 Aug 5, 2024
0.1.0 Jul 18, 2024

#326 in WebSocket

Download history 388/week @ 2024-07-30 409/week @ 2024-08-06 1/week @ 2024-08-13 19/week @ 2024-09-10 1/week @ 2024-09-17 10/week @ 2024-09-24 71/week @ 2024-10-01

265 downloads per month

MIT license

60KB
1.5K SLoC

example

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!()
    }
}

Dependencies

~0.8–8MB
~66K SLoC