Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/conduit_lwt_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,13 @@ let serve_with_default_tls ?timeout ?stop ~ctx ~certfile ~keyfile
~pass ~port callback
| No_tls -> failwith "No SSL or TLS support compiled into Conduit"

let serve ?backlog ?timeout ?stop ~(ctx:ctx) ~(mode:server) callback =
let callback flow ic oc = Lwt.catch
let serve ?backlog ?timeout ?stop
?(on_exn=(fun exn -> !Lwt.async_exception_hook exn))
~(ctx:ctx) ~(mode:server) callback =
let callback flow ic oc =
Lwt.catch
(fun () -> callback flow ic oc)
(fun exn -> !Lwt.async_exception_hook exn; Lwt.return_unit)
(fun exn -> on_exn exn; Lwt.return_unit)
in
match mode with
| `TCP (`Port port) ->
Expand Down
23 changes: 12 additions & 11 deletions lib/conduit_lwt_unix.mli
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,19 @@ val init : ?src:string -> ?tls_server_key:tls_server_key -> unit -> ctx io
via the [ctx] context to the endpoint described by [client] *)
val connect : ctx:ctx -> client -> (flow * ic * oc) io

(** [serve ?backlog ?timeout ?stop ~ctx ~mode fn] establishes a
listening connection of type [mode], using the [ctx] context.
The [stop] thread will terminate the server if it ever becomes
determined. Every connection will be served in a new
lightweight thread that is invoked via the [fn] callback.
The [fn] callback is passed the {!flow} representing the
client connection and the associated input {!ic} and output
{!oc} channels. If the callback raises an exception, it is
passed to [!Lwt.async_exception_hook]. *)
(** [serve ?backlog ?timeout ?stop ?on_exn ~ctx ~mode fn]
establishes a listening connection of type [mode], using the [ctx]
context. The [stop] thread will terminate the server if it ever
becomes determined. Every connection will be served in a new
lightweight thread that is invoked via the [fn] callback. The
[fn] callback is passed the {!flow} representing the client
connection and the associated input {!ic} and output {!oc}
channels. If the callback raises an exception, it is passed to
[on_exn] (by default, to !Lwt.async_exception_hook). *)
val serve :
?backlog:int -> ?timeout:int -> ?stop:(unit io) -> ctx:ctx ->
mode:server -> (flow -> ic -> oc -> unit io) -> unit io
?backlog:int -> ?timeout:int -> ?stop:(unit io) ->
?on_exn:(exn -> unit) -> ctx:ctx -> mode:server ->
(flow -> ic -> oc -> unit io) -> unit io

(** [endp_of_flow flow] retrieves the original {!Conduit.endp}
from the established [flow] *)
Expand Down