exercises

Log | Files | Refs | README

commit 4ea903382eda05f3da1b8d83d54eb2a9dcff3c78
parent 5d8af9cdd7d664569998db6f327d98b89828f519
Author: ling0x <ling0x@users.noreply.github.com>
Date:   Sat, 20 Jun 2026 11:51:05 +0100

refactor

Diffstat:
Masync_programming_in_rust/event_queue/src/poll.rs | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/async_programming_in_rust/event_queue/src/poll.rs b/async_programming_in_rust/event_queue/src/poll.rs @@ -1 +1,59 @@ -//! This contains the main abstraction, which is a think layer over `epoll`. +//! This contains the main abstraction, which is a thin layer over `epoll`. +//! There are two main abstractions over epoll. One is a structure called +//! `Poll` and the other is called `Registry` + +/// Its convenient to use `io::Result` type since most errors will stem from one +/// of our calls into the operating system, and an operating system error can +/// be mapped to an `io::Error` type +use std::{ + io::{self, Result}, + net::TcpStream, +}; + +type Events = Vec<ffi::Events>; + +/// Poll is a struct that represents the event queue itself. +pub struct Poll { + registry: Registry, +} + +impl Poll { + /// Creates a new event queue + pub fn new() -> Result<Self> { + todo!() + } + + /// Returns a reference to the registry that can be used to register + /// interest to be notified about new events + pub fn registry(&self) -> &Registry { + &self.registry + } + + /// Blocks the thread it's called on until an event is ready or it times + /// out, whichever occurs first + pub fn poll(&mut self, events: &mut Events, timeout: Option<i32>) -> Result<()> { + todo!() + } +} + +/// While `Poll` represents the event queue, `Registry` is a handle that allows +/// us to register interest in new events +pub struct Registry { + raw_fd: i32, +} + +impl Registry { + /// `Registry` will only have one method: `register` + /// https://docs.rs/mio/0.8.8/mio/struct.Registry.html + /// The `interests` argument will indicate what kind of events we want our + /// event queue to keep track of + pub fn register(&self, source: &TcpStream, token: usize, interests: i32) -> Result<()> { + todo!() + } +} + +impl Drop for Registry { + fn drop(&mut self) { + todo!() + } +}