<commit_before>(*
 * Copyright (c) 2012-2014 <NAME> <<EMAIL>>
 *
 * 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.
 *
 *)

(** Connection establishment using the
    {{:http://ocsigen.org/lwt/api/Lwt_unix}Lwt_unix} library *) 

(** Set of supported client connections that are supported by this module. *)
type client = [
  | `OpenSSL of string * Ipaddr.t * int (** Use OpenSSL to connect to the given [host], [ip], [port] tuple via TCP *)
  | `TCP of Ipaddr.t * int (** Use TCP to connect to the given [ip], [port] tuple. *)
  | `Unix_domain_socket of string (** Use UNIX domain sockets to connect to a socket on the [path]. *)
  | `Vchan of int * string (** Connect to the remote VM on the [domid], [port] tuple. *)
] with sexp

(** Set of supported listening mechanisms that are supported by this module. *)
type server = [
  | `OpenSSL of
      [ `Crt_file_path of string ] *
      [ `Key_file_path of string ] *
      [ `Password of bool -> string | `No_password ] *
      [ `Port of int ]
  | `TCP of [ `Port of int ]
  | `Unix_domain_socket of [ `File of string ]
  | `Vchan of int * string
] with sexp

type 'a io = 'a Lwt.t
type ic = Lwt_io.input_channel
type oc = Lwt_io.output_channel
type flow with sexp

type tls_server_key = [
 | `None
 | `OpenSSL of
    [ `Crt_file_path of string ] *
    [ `Key_file_path of string ] *
    [ `Password of bool -> string | `No_password ]
]

type ctx
val init : ?src:string -> ?tls_server_key:tls_server_key -> unit -> ctx io
val default_ctx : ctx

val connect : ctx:ctx -> client -> (flow * ic * oc) io

val serve :
  ?timeout:int -> ?stop:(unit io) -> ctx:ctx ->
   mode:server -> (flow -> ic -> oc -> unit io) -> unit io

val endp_of_flow : flow -> Conduit.endp
val endp_to_client : ctx:ctx -> Conduit.endp -> client io
(** Use the configuration of the server to interpret how to handle a
    particular endpoint from the resolver into a concrete
    implementation of type [client] *)

val endp_to_server : ctx:ctx -> Conduit.endp -> server io
<commit_msg>improve conduit_lwt_unix docs<commit_after>(*
 * Copyright (c) 2012-2014 <NAME> <<EMAIL>>
 *
 * 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.
 *
 *)

(** Connection establishment using the
    {{:http://ocsigen.org/lwt/api/Lwt_unix}Lwt_unix} library *) 

(** Set of supported client connections that are supported by this module. *)
type client = [
  | `OpenSSL of string * Ipaddr.t * int (** Use OpenSSL to connect to the given [host], [ip], [port] tuple via TCP *)
  | `TCP of Ipaddr.t * int (** Use TCP to connect to the given [ip], [port] tuple. *)
  | `Unix_domain_socket of string (** Use UNIX domain sockets to connect to a socket on the [path]. *)
  | `Vchan of int * string (** Connect to the remote VM on the [domid], [port] tuple. *)
] with sexp

(** Set of supported listening mechanisms that are supported by this module. *)
type server = [
  | `OpenSSL of
      [ `Crt_file_path of string ] *
      [ `Key_file_path of string ] *
      [ `Password of bool -> string | `No_password ] *
      [ `Port of int ]
  | `TCP of [ `Port of int ]
  | `Unix_domain_socket of [ `File of string ]
  | `Vchan of int * string
] with sexp

type 'a io = 'a Lwt.t
type ic = Lwt_io.input_channel
type oc = Lwt_io.output_channel

(** Type of an established connection *)
type flow with sexp

(** Type describing where to locate an OpenSSL-format
    key in the filesystem *)
type tls_server_key = [
 | `None
 | `OpenSSL of
    [ `Crt_file_path of string ] *
    [ `Key_file_path of string ] *
    [ `Password of bool -> string | `No_password ]
]

(** State handler for an active conduit *)
type ctx

(** Default context that listens on all source addresses with
    no TLS certificate associated with the Conduit *)
val default_ctx : ctx

(** [init ?src ?tls_server_key] will initialize a Unix conduit
    that binds to the [src] interface if specified.  If TLS server
    connections are used, then [tls_server_key] must contain a
    valid certificate to be used to advertise a TLS connection *)
val init : ?src:string -> ?tls_server_key:tls_server_key -> unit -> ctx io

(** [connect ~ctx client] establishes an outgoing connection
    via the [ctx] context to the endpoint described by [client] *)
val connect : ctx:ctx -> client -> (flow * ic * oc) io

(** [serve ?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 *)
val serve :
  ?timeout:int -> ?stop:(unit io) -> ctx:ctx ->
   mode:server -> (flow -> ic -> oc -> unit io) -> unit io

(** [endp_of_flow flow] retrieves the original {!Conduit.endp}
    from the established [flow] *)
val endp_of_flow : flow -> Conduit.endp

(** [endp_to_client ~ctx endp] converts an [endp] into a
    a concrete connection mechanism of type [client] *)
val endp_to_client : ctx:ctx -> Conduit.endp -> client io

(** [endp_to_server ~ctx endp] converts an [endp] into a
    a concrete connection mechanism of type [client] *)
val endp_to_server : ctx:ctx -> Conduit.endp -> server io

{'fraction_non_alphanumeric': 0.09992337164750958, 'fraction_numerical': 0.0024521072796934865, 'mean_word_length': 3.554082344731333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3709358', 'n_tokens_mistral': 2026, 'n_tokens_neox': 1923, 'n_words': 854}