Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let use_chans chans=
- let rec use_chans_in rest all =
- match rest with
- | [] -> let%lwt () = Lwt_unix.sleep 5.0 in
- let%lwt () = Lwt_io.printf "will use_chans\n%!" in
- let%lwt () = Lwt_io.flush Lwt_io.stdout in
- use_chans_in all all
- | h::t ->
- let%lwt ()=Lwt_io.fprintf h "hello socket world\n" in
- use_chans_in t all
- in
- use_chans_in chans chans
- let init_socket addr port count=
- let rec init_socket_in add port count chans =
- let inet_addr = (Unix.inet_addr_of_string addr) in
- let sockaddr = Unix.ADDR_INET (inet_addr, port) in
- let domain = Unix.domain_of_sockaddr sockaddr in
- (*let sock = Lwt_unix.socket domain Lwt_unix.SOCK_STREAM 0 in*)
- let sock = Lwt_unix.socket domain Unix.SOCK_STREAM 0 in
- let%lwt () = Lwt_unix.connect sock sockaddr in
- let outchan = (Lwt_io.of_fd ~mode:Lwt_io.output sock) in
- let%lwt ()=Lwt_io.fprintf outchan "hello socket world\n" in
- if count==0 then begin
- let%lwt () = Lwt_io.printf "READY! will use_chans\n%!" in
- let%lwt () = Lwt_io.flush Lwt_io.stdout in
- let%lwt () = Lwt_unix.sleep 5.0 in
- use_chans (outchan::chans)
- end else begin
- init_socket_in addr port (count-1) (outchan::chans)
- end
- in
- init_socket_in addr port count []
- let () =
- let addr = Sys.argv.(1) in
- let port = int_of_string(Sys.argv.(2)) in
- let count= int_of_string(Sys.argv.(3)) in
- Lwt_main.run (init_socket addr port count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement