File tree Expand file tree Collapse file tree 6 files changed +16
-11
lines changed
Expand file tree Collapse file tree 6 files changed +16
-11
lines changed Original file line number Diff line number Diff line change 4141 | `TCP -> LUN.Tcp_client. connect sa
4242END
4343
44- let serve ~mode ~sockaddr ?timeout callback =
44+ let serve ~mode ~sockaddr ?stop ? timeout callback =
4545IFDEF HAVE_LWT_SSL THEN
4646 match mode with
47- | `TCP -> LUN.Tcp_server. init ~sockaddr ?timeout callback
47+ | `TCP -> LUN.Tcp_server. init ~sockaddr ?stop ? timeout callback
4848 | `SSL (`Crt_file_path certfile , `Key_file_path keyfile ) ->
49- Lwt_unix_net_ssl.Server. init ~certfile ~keyfile ?timeout sockaddr callback
49+ Lwt_unix_net_ssl.Server. init ~certfile ~keyfile
50+ ?stop ?timeout sockaddr callback
5051ELSE
5152 match mode with
52- | `TCP -> LUN.Tcp_server. init ~sockaddr ?timeout callback
53+ | `TCP -> LUN.Tcp_server. init ~sockaddr ?stop ? timeout callback
5354 | `SSL (`Crt_file_path certfile , `Key_file_path keyfile ) ->
5455 fail (Failure " No SSL support compiled into Conduit" )
5556END
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ val connect :
3131val serve :
3232 mode :server_mode ->
3333 sockaddr :Lwt_unix .sockaddr ->
34+ ?stop : (unit -> bool ) ->
3435 ?timeout : int -> (ic -> oc -> unit io ) -> unit io
3536
3637val close_in : 'a Lwt_io .channel -> unit
Original file line number Diff line number Diff line change @@ -58,17 +58,17 @@ module Tcp_server = struct
5858 Lwt_unix. setsockopt client Lwt_unix. TCP_NODELAY true ;
5959 let ic = Lwt_io. of_fd ~mode: Lwt_io. input client in
6060 let oc = Lwt_io. of_fd ~mode: Lwt_io. output client in
61-
61+
6262 let c = callback ic oc in
6363 let events = match timeout with
6464 | None -> [c]
6565 | Some t -> [c; (Lwt_unix. sleep (float_of_int t)) ] in
6666 let _ = Lwt. pick events >> = fun () -> close (ic,oc) in
6767 return ()
68-
69- let init ~sockaddr ?timeout callback =
68+
69+ let init ~sockaddr ?( stop = ( fun () -> true )) ? timeout callback =
7070 let s = init_socket sockaddr in
71- while_lwt true do
71+ while_lwt (stop () ) do
7272 Lwt_unix. accept s >> =
7373 process_accept ?timeout callback
7474 done
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ module Tcp_server : sig
3232
3333 val init :
3434 sockaddr :Lwt_unix .sockaddr ->
35+ ?stop : (unit -> bool ) ->
3536 ?timeout : int ->
3637 (input channel -> output channel -> unit Lwt .t ) ->
3738 unit Lwt .t
Original file line number Diff line number Diff line change @@ -67,13 +67,14 @@ module Server = struct
6767 let _ = Lwt. pick events >> = fun () -> close (ic,oc) in
6868 return ()
6969
70- let init ?(nconn =20 ) ?password ~certfile ~keyfile ?timeout sa callback =
70+ let init ?(nconn =20 ) ?password ~certfile ~keyfile
71+ ?(stop = (fun () -> true )) ?timeout sa callback =
7172 let s = listen ~nconn ?password ~certfile ~keyfile sa in
7273 let cont = ref true in
73- while_lwt ! cont do
74+ while_lwt ! cont && (stop () ) do
7475 try_lwt begin
7576 accept s >> = process_accept ~timeout callback
76- end with
77+ end with
7778 | Lwt. Canceled -> cont := false ; return ()
7879 | _ -> return ()
7980 done
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ module Server : sig
3838 ?password : (bool -> string ) ->
3939 certfile :string ->
4040 keyfile :string ->
41+ ?stop : (unit -> bool ) ->
4142 ?timeout : int ->
4243 Lwt_unix .sockaddr ->
4344 (Lwt_io .input_channel -> Lwt_io .output_channel -> unit Lwt .t ) ->
You can’t perform that action at this time.
0 commit comments