-
Notifications
You must be signed in to change notification settings - Fork 0
input with timeout #3
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
base: main
Are you sure you want to change the base?
Conversation
| Bytes.create size | ||
|
|
||
| type decompress_state = | ||
| type transduce_state = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unusual name, I would have gone with "codec" instead of "transducer" I think. Or maybe just "compressor".
| end | ||
|
|
||
| (** Input stream where [input] takes a timeout. | ||
| This is useful for network operations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for so many other operations!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I don't know a lot of IOs that are truly non blocking besides networking? At least on linux, which is what I know, normal IOs on the filesystem are always blocking, for example.
| val map_char : (char -> char) -> #t -> t | ||
| (** Transform the stream byte by byte *) | ||
|
|
||
| val input_with_timeout : #t_with_timeout -> float -> bytes -> int -> int -> int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstrings here mention "read" more often than "input", maybe these functions should also be named read_*. (Not sure if that would create name clashes elsewhere.)
| len := !len - n | ||
| done | ||
|
|
||
| method seek i = ignore (Unix.lseek fd i Unix.SEEK_SET : int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dangerous to ignore the return value. To be on the safe side, I would check that the return value is equal to i.
| end = struct | ||
| open Iostream | ||
|
|
||
| let now_ = Unix.gettimeofday |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I remember that gettimeofday is not guaranteeed to be monotonic? That could lead to some suprises. Not sure we can get to clock_gettime via the standard library though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly we cannot…
see: ocaml/ocaml#12858 :(
| open Iostream | ||
|
|
||
| let now_ = Unix.gettimeofday | ||
| let short_timeout_ : float = 2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's so relative!
| | Unix.Unix_error ((Unix.EAGAIN | Unix.EWOULDBLOCK), _, _) -> | ||
| (* sleep *) | ||
| true | ||
| | Unix.Unix_error ((Unix.ECONNRESET | Unix.ESHUTDOWN | Unix.EPIPE), _, _) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure these are all possible errors, maybe add a default exception handler as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the other exceptions I'd let bubble down, these are specifically handled here because they're the ones I can think of that related to either blocking, or the FD being actually closed.
| in | ||
|
|
||
| let input_with_timeout t buf i len : int = | ||
| let deadline = now_ () +. t in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the clock is non-monotonic, then the deadline can end up being in the past, but read would still be called at least once. I'm not sure how best to handle that.
wintersteiger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just a number of small nitpicks to complain about :-)
Co-authored-by: Christoph M. Wintersteiger <[email protected]>
Co-authored-by: Christoph M. Wintersteiger <[email protected]>
No description provided.