Commit 100fc224 authored by MARCHE Claude's avatar MARCHE Claude

attempt to capture connection error (Unix_error(_,"connect",_))

parent 6e7481f0
......@@ -19,14 +19,33 @@ let is_connected () = !socket <> None
let client_connect socket_name =
if !socket <> None then raise AlreadyConnected;
if Sys.os_type = "Win32" then begin
let name = "\\\\.\\pipe\\" ^ socket_name in
socket := Some (Unix.openfile name [Unix.O_RDWR] 0)
end else begin
try
if Sys.os_type = "Win32" then raise Exit;
let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
Unix.connect sock (Unix.ADDR_UNIX socket_name);
socket := Some sock
end
try
Unix.connect sock (Unix.ADDR_UNIX socket_name);
socket := Some sock
with
| Unix.Unix_error(err, func, arg) ->
Format.eprintf "socket connection failed: %s (%s,%s)@." (Unix.error_message err) func arg;
Format.eprintf "falling back to a named socket@.";
raise Exit
| e ->
Format.eprintf "Unix.connect failed for some unexpected reason: %s@\nAborting.@."
(Printexc.to_string e);
exit 2
with Exit ->
try
let name = "\\\\.\\pipe\\" ^ socket_name in
let sock = Unix.openfile name [Unix.O_RDWR] 0 in
socket := Some sock
with
| Unix.Unix_error(err, func, arg) ->
Format.eprintf "opening named socket failed: %s (%s,%s)@." (Unix.error_message err) func arg;
| e ->
Format.eprintf "Unix.openfile failed for some unexpected reason: %s@\nAborting.@."
(Printexc.to_string e);
exit 2
let client_disconnect () =
match !socket with
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment