@@ -74,21 +74,21 @@ let is_full ic = ic.cur = 0 && ic.max = Bytes.length ic.buf
74
74
let fill_buf ~buffered ic timeout =
75
75
let buf_size = Bytes. length ic.buf in
76
76
let fill_no_exc timeout len =
77
- let l, _, _ = Unix. select [ ic.fd] [] [] timeout in
78
- if l <> [] then (
77
+ Xapi_stdext_unix.Unixext. with_socket_timeout ic.fd timeout @@ fun () ->
78
+ try
79
79
let n = Unix. read ic.fd ic.buf ic.max len in
80
80
ic.max < - n + ic.max ;
81
81
if n = 0 && len <> 0 then raise Eof ;
82
82
n
83
- ) else
84
- - 1
83
+ with Unix. Unix_error (Unix. (EAGAIN | EWOULDBLOCK ), _ , _ ) -> - 1
85
84
in
86
85
(* If there's no space to read, shift *)
87
86
if ic.max = buf_size then shift ic ;
88
87
let space_left = buf_size - ic.max in
89
88
(* Read byte one by one just do make sure we don't buffer too many chars *)
90
89
let n =
91
- fill_no_exc timeout (if buffered then space_left else min space_left 1 )
90
+ fill_no_exc (Some timeout)
91
+ (if buffered then space_left else min space_left 1 )
92
92
in
93
93
(* Select returned nothing to read *)
94
94
if n = - 1 then raise Timeout ;
@@ -97,7 +97,11 @@ let fill_buf ~buffered ic timeout =
97
97
let tofillsz =
98
98
if buffered then buf_size - ic.max else min (buf_size - ic.max) 1
99
99
in
100
- ignore (fill_no_exc 0.0 tofillsz)
100
+ (* cannot use 0 here, for select that'd mean timeout immediately, for
101
+ setsockopt it would mean no timeout.
102
+ So use a very short timeout instead
103
+ *)
104
+ ignore (fill_no_exc (Some 1e-6 ) tofillsz)
101
105
)
102
106
103
107
(* * Input one line terminated by \n *)
0 commit comments