-
-
Save co-dan/b5b1019afc3363eaf2e8d987c185de07 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Lwt | |
(* cannot load this file up in utop without the next two lines *) | |
(* #require "conduit" | |
* #require "conduit-lwt-unix" *) | |
open Conduit | |
open Conduit_lwt_unix | |
let resolve_addr (s: string) : endp Lwt.t = | |
let open Resolver_lwt_unix in | |
let uri = Uri.of_string s in | |
Resolver_lwt.resolve_uri ~uri system | |
let client_of_addr (s: string) : client Lwt.t = | |
resolve_addr s >>= endp_to_client ~ctx:default_ctx | |
(* TODO: errror handling etc. Conflicts with Lwt_io.with_connection? *) | |
let with_connection (s: string) (f : ic -> oc -> 'a Lwt.t) : 'a Lwt.t = | |
let open Lwt_io in | |
client_of_addr s >>= fun cl -> | |
connect ~ctx:default_ctx cl >>= fun (_,ic,oc) -> | |
f ic oc >>= fun r -> | |
close oc >>= fun _ -> | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment