mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-06 03:05:29 -05:00
fix: when reading from unix FD, use a loop to handle signals
This commit is contained in:
parent
f316e66c15
commit
6536bfeeb3
1 changed files with 14 additions and 4 deletions
|
|
@ -92,10 +92,20 @@ module Byte_stream = struct
|
||||||
{ bs_fill_buf=(fun () ->
|
{ bs_fill_buf=(fun () ->
|
||||||
if !i >= !len then (
|
if !i >= !len then (
|
||||||
i := 0;
|
i := 0;
|
||||||
let (to_read,_,_) = Unix.select [ic] [] [] timeout in
|
|
||||||
if to_read = [] then raise Timeout;
|
let rec wait() =
|
||||||
try len := Unix.read ic buf 0 (Bytes.length buf)
|
let to_read,_,_ = Unix.select [ic] [] [] timeout in
|
||||||
with Unix.Unix_error ((EAGAIN | EWOULDBLOCK), _, _) -> ();
|
if to_read = [] then raise Timeout;
|
||||||
|
read()
|
||||||
|
and read() =
|
||||||
|
try len := Unix.read ic buf 0 (Bytes.length buf)
|
||||||
|
with
|
||||||
|
| Unix.Unix_error (EAGAIN, _, _) -> read()
|
||||||
|
| Unix.Unix_error (EWOULDBLOCK, _, _) ->
|
||||||
|
(* FIXME: we should decrease the timeout by however long was spent in [select] *)
|
||||||
|
wait()
|
||||||
|
in
|
||||||
|
wait()
|
||||||
);
|
);
|
||||||
buf, !i,!len - !i);
|
buf, !i,!len - !i);
|
||||||
bs_consume=(fun n -> i := !i + n);
|
bs_consume=(fun n -> i := !i + n);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue