Cope with (some) instances of EPIPE
This commit is contained in:
parent
b9eda344cc
commit
e31931b406
22
relay.ml
22
relay.ml
|
@ -38,12 +38,15 @@ let dispatch_message n ch m =
|
||||||
send_error ch "Message not understood" (Message.sexp_of_message m)
|
send_error ch "Message not understood" (Message.sexp_of_message m)
|
||||||
|
|
||||||
let flush_output mtx flush_control cout =
|
let flush_output mtx flush_control cout =
|
||||||
while Event.poll (Event.receive flush_control) = None do
|
let rec loop () =
|
||||||
Mutex.lock mtx;
|
match Event.poll (Event.receive flush_control) with
|
||||||
flush cout;
|
| Some () -> ()
|
||||||
Mutex.unlock mtx;
|
| None ->
|
||||||
Thread.delay 0.1
|
Mutex.lock mtx;
|
||||||
done
|
let ok = try flush cout; true with _ -> false in
|
||||||
|
Mutex.unlock mtx;
|
||||||
|
if ok then (Thread.delay 0.1; loop ()) else ()
|
||||||
|
in loop ()
|
||||||
|
|
||||||
let relay_handler write_sexp n m =
|
let relay_handler write_sexp n m =
|
||||||
write_sexp m
|
write_sexp m
|
||||||
|
@ -73,7 +76,10 @@ let relay_main peername cin cout =
|
||||||
| End_of_file ->
|
| End_of_file ->
|
||||||
printf "INFO: Disconnecting %s normally.\n%!" (endpoint_name peername)
|
printf "INFO: Disconnecting %s normally.\n%!" (endpoint_name peername)
|
||||||
| Sexp.Syntax_error explanation ->
|
| Sexp.Syntax_error explanation ->
|
||||||
send_sexp_syntax_error write_sexp explanation);
|
send_sexp_syntax_error write_sexp explanation
|
||||||
|
| Sys_error message ->
|
||||||
|
printf "WARNING: Disconnected by Sys_error %s\n%!" message
|
||||||
|
);
|
||||||
Node.unbind_all n;
|
Node.unbind_all n;
|
||||||
Event.sync (Event.send flush_control ())
|
Event.sync (Event.send flush_control ())
|
||||||
|
|
||||||
|
@ -83,7 +89,7 @@ let start_relay' (s, peername) =
|
||||||
connection_count := 1 + !connection_count;
|
connection_count := 1 + !connection_count;
|
||||||
relay_main peername cin cout;
|
relay_main peername cin cout;
|
||||||
connection_count := 0 + !connection_count;
|
connection_count := 0 + !connection_count;
|
||||||
flush cout;
|
try flush cout with _ -> ();
|
||||||
close s
|
close s
|
||||||
|
|
||||||
let start_relay (s, peername) =
|
let start_relay (s, peername) =
|
||||||
|
|
Loading…
Reference in New Issue