retry rcon connection indefinitely
This commit is contained in:
parent
bcdab23a72
commit
140e8897b1
|
@ -1,7 +1,7 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=factorio-matrix bridge
|
Description=factorio-matrix bridge
|
||||||
Requires=factorio.service
|
#Requires=factorio.service
|
||||||
After=factorio.service
|
#After=factorio.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/opt/factorio-bridge/factorio_bridge.exe -config /opt/factorio-bridge/bridge.conf
|
ExecStart=/opt/factorio-bridge/factorio_bridge.exe -config /opt/factorio-bridge/bridge.conf
|
||||||
|
|
|
@ -168,9 +168,13 @@ let matrix_message_stream ~homeserver ~token ~(state : string option)
|
||||||
|
|
||||||
let rcon_writer ~(host : string) ~(port : int) ~(password : string) : string Pipe.Writer.t =
|
let rcon_writer ~(host : string) ~(port : int) ~(password : string) : string Pipe.Writer.t =
|
||||||
let reader_func pipe_reader =
|
let reader_func pipe_reader =
|
||||||
let%bind (socket, reader, writer) =
|
let rec retry_conn () =
|
||||||
Tcp.connect (Tcp.Where_to_connect.of_host_and_port {host; port;})
|
try_with (fun () -> Tcp.connect (Tcp.Where_to_connect.of_host_and_port {host; port;}))
|
||||||
|
>>= function
|
||||||
|
| Ok x -> return x
|
||||||
|
| Error _ -> let%bind () = Clock.after (Time.Span.of_sec 10.) in retry_conn ()
|
||||||
in
|
in
|
||||||
|
let%bind (socket, reader, writer) = retry_conn () in
|
||||||
ignore socket;
|
ignore socket;
|
||||||
let send_packet (id : int) (typ : int) (body : string) =
|
let send_packet (id : int) (typ : int) (body : string) =
|
||||||
let body = String.concat [body; "\x00\x00"] in
|
let body = String.concat [body; "\x00\x00"] in
|
||||||
|
|
Loading…
Reference in New Issue