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
5 changes: 4 additions & 1 deletion bin/cohttp_server_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ let start_server docroot port host index verbose cert key () =
| Some c, Some k -> `TLS (`Crt_file_path c, `Key_file_path k, `No_password, `Port port)
| _ -> `TCP (`Port port)
in
Server.create ~mode config
Conduit_lwt_unix.init ~src:host ()
>>= fun ctx ->
let ctx = Cohttp_lwt_unix_net.init ~ctx () in
Server.create ~ctx ~mode config

let lwt_start_server docroot port host index verbose cert key =
Lwt_main.run (start_server docroot port host index verbose cert key ())
Expand Down
2 changes: 1 addition & 1 deletion lwt/cohttp_lwt_unix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Client = struct
Cohttp_lwt.Make_client
(Cohttp_lwt_unix_io)(Request)(Response)(Cohttp_lwt_unix_net)

let custom_ctx = Cohttp_lwt_unix_net.custom_ctx
let custom_ctx = Cohttp_lwt_unix_net.init
end

module Server_core =
Expand Down
10 changes: 2 additions & 8 deletions lwt/cohttp_lwt_unix_net.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,20 @@ open Lwt

module IO = Cohttp_lwt_unix_io

type 'a io = 'a Lwt.t
type ic = Lwt_io.input_channel
type oc = Lwt_io.output_channel
type ctx = {
ctx: Conduit_lwt_unix.ctx;
resolver: Resolver_lwt.t;
} with sexp_of

let init ?(resolver=Resolver_lwt_unix.system)
?(ctx=Conduit_lwt_unix.default_ctx) () =
let init ?(ctx=Conduit_lwt_unix.default_ctx)
?(resolver=Resolver_lwt_unix.system) () =
{ ctx; resolver }

let default_ctx = {
resolver = Resolver_lwt_unix.system;
ctx = Conduit_lwt_unix.default_ctx;
}

let custom_ctx ?(ctx=Conduit_lwt_unix.default_ctx) ?(resolver=Resolver_lwt_unix.system) () =
{ ctx; resolver }

let connect_uri ~ctx uri =
Resolver_lwt.resolve_uri ~uri ctx.resolver
>>= fun endp ->
Expand Down
43 changes: 43 additions & 0 deletions lwt/cohttp_lwt_unix_net.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(*
* Copyright (c) 2015 David Sheets <sheets@alum.mit.edu>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*)

(** Basic satisfaction of {! Cohttp_lwt.Net } *)

module IO : Cohttp.S.IO
with type 'a t = 'a Lwt.t
and type ic = Lwt_io.input_channel
and type oc = Lwt_io.output_channel
and type conn = Conduit_lwt_unix.flow

type ctx = {
ctx : Conduit_lwt_unix.ctx;
resolver : Resolver_lwt.t;
} with sexp_of

val init : ?ctx:Conduit_lwt_unix.ctx -> ?resolver:Resolver_lwt.t -> unit -> ctx

val default_ctx : ctx

val connect_uri :
ctx:ctx ->
Uri.t ->
(Conduit_lwt_unix.flow * Conduit_lwt_unix.ic * Conduit_lwt_unix.oc) Lwt.t

val close_in : 'a Lwt_io.channel -> unit
val close_out : 'a Lwt_io.channel -> unit

val close : 'a Lwt_io.channel -> 'b Lwt_io.channel -> unit