Module File_descr_watcher_intf

module File_descr_watcher_intf: sig .. end
File_descr_watcher_intf.S provides an API for for watching a set of file descriptors to see if they are ready for reading or writing.

We have two implementations, one using epoll, and one using select.

None of the functions need to be thread-safe, with the exception of thread_safe_check. So that implementations can easily do non-thread-safe actions, checking for ready I/O is always done in three steps:

1. pre_check, while holding the async lock 2. thread_safe_check, while not holding the async lock 3. post_check, while holding the async lock


val __pa_ounit_275876e34cf609db118f3d84b799a790 : string

File_descr_watcher_intf.S provides an API for for watching a set of file descriptors to see if they are ready for reading or writing.

We have two implementations, one using epoll, and one using select.

None of the functions need to be thread-safe, with the exception of thread_safe_check. So that implementations can easily do non-thread-safe actions, checking for ready I/O is always done in three steps:

1. pre_check, while holding the async lock 2. thread_safe_check, while not holding the async lock 3. post_check, while holding the async lock

module Post: sig .. end
module Timeout: sig .. end
module type S = sig .. end

File_descr_watcher_intf.S provides an API for for watching a set of file descriptors to see if they are ready for reading or writing.

We have two implementations, one using epoll, and one using select.

None of the functions need to be thread-safe, with the exception of thread_safe_check. So that implementations can easily do non-thread-safe actions, checking for ready I/O is always done in three steps:

1. pre_check, while holding the async lock 2. thread_safe_check, while not holding the async lock 3. post_check, while holding the async lock

A file-descr-watcher is essentially a map from File_descr.t to bool Read_write.t, which defines the set of file descriptors being watched, and for each file descriptor, whether it is being watched for read, write, or both. If a file descriptor is not being watched for neither, it is not in the map.

create ~num_file_descrs creates a new file-descr-watcher that is able to watch file descriptors in

 [0, num_file_descrs) 
.

set alters the map of file descriptors being watched. It will take effect on the next call to thread_safe_check. Calling set fd with { read = false, write = false } removes fd from the map.

iter t ~f iterates over every file descriptor in the map, apply f to it once for each of {`Read,`Write} that it is being watched for.

pre_check t does whatever non-thread-safe work is necessary to prepare for the system call that checks file descriptors being ready for read or write. pre_check does not side effect t.

thread_safe_check t pre ~timeout checks the file descriptors for their status and returns when at least one is available, or the timeout passes. thread_safe_check does not side effect t. Unlike the rest of the functions in this module, thread_safe_check is thread safe.

post_check t check_result returns the file descriptors available for read and write. Any file descriptor appearing in post for read must have been watched for read, as per set. Similarly for write.