-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfdwatcher.ml
More file actions
34 lines (29 loc) · 948 Bytes
/
Copy pathfdwatcher.ml
File metadata and controls
34 lines (29 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(** Fdwatcher - The main event loop. Agnostic to the type of file descriptors
involved.*)
open Printf
open Globals
open Printexc
let fdset = ref []
let cbtable = Hashtbl.create 1024
let add_fd (evpair:fname_and_fd) (fd_other:fname_and_fd) (callback:fname_and_fd->fname_and_fd->unit) =
let (fname,fd) = evpair in
fdset := (fd::!fdset);
Hashtbl.replace cbtable fd (callback,(evpair,fd_other))
let del_fd fd =
fdset:=List.filter (fun l->l<>fd) !fdset
let start_watch () =
while (true)
do
let (fds,_,_) = try Unix.select !fdset [] [] (-1.)
with e->
([],[],[])
in
List.iter (fun elt->
let (func,(evd,fd_other)) = Hashtbl.find cbtable elt in
try (* Never fail *)
func evd fd_other
with e->
let wtf = Printexc.to_string e in
logprint "%s\n" wtf
) fds
done