Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use List.iter instead of Hashtbl.iter when we scan file-descriptors #45

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions lib/miou_unix.ml
Original file line number Diff line number Diff line change
@@ -25,12 +25,33 @@ let bind_and_listen ?(backlog = 64) ?(reuseaddr = true) ?(reuseport = true)
Unix.bind fd sockaddr;
Unix.listen fd backlog

module File_descrs = Hashtbl.Make (struct
type t = Unix.file_descr
module File_descrs = struct
type 'a t = { mutable contents: (Unix.file_descr * 'a) list }

let equal a b = Int.equal (Obj.magic a) (Obj.magic b)
let hash v = Obj.magic v land max_int
end)
let find tbl fd = List.assq fd tbl.contents

let remove tbl fd =
let contents =
List.fold_left
(fun acc (k, v) -> if k == fd then acc else (k, v) :: acc)
[] tbl.contents
in
tbl.contents <- contents

let iter f tbl = List.iter (fun (k, v) -> f k v) tbl.contents

let replace tbl fd v' =
let contents =
List.fold_left
(fun acc (k, v) -> if k == fd then (k, v') :: acc else (k, v) :: acc)
[] tbl.contents
in
tbl.contents <- contents

let add tbl k v = tbl.contents <- (k, v) :: tbl.contents
let clear tbl = tbl.contents <- []
let create _ = { contents= [] }
end

type elt = { time: float; syscall: Miou.syscall; mutable cancelled: bool }