1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071(*{{{ Copyright (c) 2012 Anil Madhavapeddy <anil@recoil.org>
*
* 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.
*
}}}*)(* Miscellaneous net-helpers used by Cohttp. Ideally, these will disappear
* into some connection-management framework such as andrenth/release *)openLwt.InfixmoduleIO=Iotypectx={ctx:Conduit_lwt_unix.ctx;resolver:Resolver_lwt.t}[@@derivingsexp_of]letinit?(ctx=Lazy.forceConduit_lwt_unix.default_ctx)?(resolver=Resolver_lwt_unix.system)()={ctx;resolver}letdefault_ctx=lazy{resolver=Resolver_lwt_unix.system;ctx=Lazy.forceConduit_lwt_unix.default_ctx;}typeendp=Conduit.endptypeclient=Conduit_lwt_unix.clientletresolve~ctxuri=Resolver_lwt.resolve_uri~urictx.resolverlettunnelhostname(channels:IO.ic*IO.oc):client=`TLS_tunnel(`Hostnamehostname,(fstchannels).chan,sndchannels)letconnect_client~ctx:{ctx;_}client=Conduit_lwt_unix.connect~ctxclient>|=fun(flow,ic,oc)->letic=Input_channel.createicin(flow,ic,oc)letconnect_endp~ctxendp=Conduit_lwt_unix.endp_to_client~ctx:ctx.ctxendp>>=connect_client~ctxletconnect_uri~ctxuri=resolve~ctxuri>>=connect_endp~ctxletclosec=Lwt.catch(fun()->Input_channel.closec)(fune->Logs.warn(funf->f"Closing channel failed: %s"(Printexc.to_stringe));Lwt.return_unit)letclose_occ=Lwt.catch(fun()->Lwt_io.closec)(fune->Logs.warn(funf->f"Closing channel failed: %s"(Printexc.to_stringe));Lwt.return_unit)letclose_inic=Lwt.ignore_result(closeic)letclose_outoc=Lwt.ignore_result(close_ococ)letcloseicoc=Lwt.ignore_result(closeic>>=fun()->close_ococ)