Skip to content

Commit

Permalink
Use pick, not choose, to cancel timeout thread
Browse files Browse the repository at this point in the history
  • Loading branch information
andrenth committed Feb 14, 2013
1 parent fef3a7e commit 354b13e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/core/release_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ end
module Make (B : Release_buffer.S) : S with type buffer = B.t = struct
type buffer = B.t

module O = Release_util.Option

let rec interrupt_safe f =
try_lwt
f ()
Expand All @@ -50,15 +52,15 @@ module Make (B : Release_buffer.S) : S with type buffer = B.t = struct
else
lwt k = read_once fd buf offset remain in
read (offset + k) (if k = 0 then 0 else remain - k) in
let timeout = match timeout with None -> infinity | Some t -> t in
let timeout_t = (* XXX doesn't this raise??? *)
lwt () = Lwt_unix.timeout timeout in
let tmout = O.default infinity timeout in
let timeout_t =
lwt () = Lwt_unix.sleep tmout in
return `Timeout in
let read_t =
match_lwt read 0 n with
| 0 -> return `EOF
| k -> return (`Data (B.sub buf 0 k)) in
timeout_t <?> read_t
Lwt.pick [timeout_t; read_t]

let write fd buf =
let len = B.length buf in
Expand Down

0 comments on commit 354b13e

Please sign in to comment.