10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-23 04:43:45 +01:00

Router/dealer in qp_tunnel

This commit is contained in:
Anthony Scemama 2019-08-01 12:11:10 +02:00
parent 0950d03f09
commit 1e7f837d2f

View File

@ -145,8 +145,8 @@ let () =
let socket_in, socket_out = let socket_in, socket_out =
match req_or_sub with match req_or_sub with
| REQ -> | REQ ->
create_socket Zmq.Socket.rep Zmq.Socket.bind addr_in, create_socket Zmq.Socket.router Zmq.Socket.bind addr_in,
create_socket Zmq.Socket.req Zmq.Socket.connect addr_out create_socket Zmq.Socket.dealer Zmq.Socket.connect addr_out
| SUB -> | SUB ->
create_socket Zmq.Socket.sub Zmq.Socket.connect addr_in, create_socket Zmq.Socket.sub Zmq.Socket.connect addr_in,
create_socket Zmq.Socket.pub Zmq.Socket.bind addr_out create_socket Zmq.Socket.pub Zmq.Socket.bind addr_out
@ -156,6 +156,7 @@ let () =
Zmq.Socket.subscribe socket_in ""; Zmq.Socket.subscribe socket_in "";
(*
let action = let action =
if verbose then if verbose then
begin begin
@ -193,11 +194,23 @@ let () =
Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out) Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out)
end end
in in
*)
let action_in =
match req_or_sub with
| REQ -> (fun () -> Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out)
| SUB -> (fun () -> Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out)
in
let action_out =
match req_or_sub with
| REQ -> (fun () -> Zmq.Socket.recv_all socket_out |> Zmq.Socket.send_all socket_in )
| SUB -> (fun () -> () )
in
let pollitem = let pollitem =
Zmq.Poll.mask_of Zmq.Poll.mask_of
[| (socket_in, Zmq.Poll.In) |] [| (socket_in, Zmq.Poll.In) ; (socket_out, Zmq.Poll.In) |]
in in
@ -207,11 +220,11 @@ let () =
Zmq.Poll.poll ~timeout:1000 pollitem Zmq.Poll.poll ~timeout:1000 pollitem
in in
match polling.(0) with match polling with
| Some Zmq.Poll.In -> action () | [| Some Zmq.Poll.In ; Some Zmq.Poll.In |] -> ( action_out () ; action_in () )
| None -> () | [| _ ; Some Zmq.Poll.In |] -> action_out ()
| Some Zmq.Poll.In_out | [| Some Zmq.Poll.In ; _ |] -> action_in ()
| Some Zmq.Poll.Out -> () | _ -> ()
done; done;
Zmq.Socket.close socket_in; Zmq.Socket.close socket_in;
@ -405,9 +418,9 @@ let () =
Printf.printf " Printf.printf "
On remote hosts, create ssh tunnel using: On remote hosts, create ssh tunnel using:
ssh -n -L %d:%s:%d -L %d:%s:%d -L %d:%s:%d -L %d:%s:%d %s & ssh -L %d:%s:%d -L %d:%s:%d -L %d:%s:%d -L %d:%s:%d %s &
Or from this host connect to clients using: Or from this host connect to clients using:
ssh -n -R %d:localhost:%d -R %d:localhost:%d -R %d:localhost:%d -R %d:localhost:%d <host> & ssh -R %d:localhost:%d -R %d:localhost:%d -R %d:localhost:%d -R %d:localhost:%d <host> &
%!" %!"
(port ) localhost (localport ) (port ) localhost (localport )
(port+1) localhost (localport+1) (port+1) localhost (localport+1)