123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122(*
* Copyright (c) 2018-2022 Tarides <contact@tarides.com>
*
* 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.
*)moduleCodec=structmoduletypeS=sigvalencode:'aIrmin.Type.t->'a->stringvaldecode:'aIrmin.Type.t->string->('a,[`Msgofstring])resultendendmoduletypeIO=sigtypeflowtypeictypeocexceptionTimeoutvalis_closed:ic->boolvalwrite_int64_be:oc->int64->unitLwt.tvalread_int64_be:ic->int64Lwt.tvalflush:oc->unitLwt.tvalwrite:oc->string->unitLwt.tvalread_into_exactly:ic->bytes->int->int->unitLwt.tvalwrite_char:oc->char->unitLwt.tvalread_char:ic->charLwt.tvalwith_timeout:float->(unit->'aLwt.t)->'aLwt.tvaltime:unit->floatendmoduletypeS=sigmoduleIO:IOtypet={ic:IO.ic;oc:IO.oc;buffer:bytes}valv:?buffer_size:int->IO.ic->IO.oc->t(** Create a new connection using [flow], [ic] and [oc] *)valis_closed:t->bool(** Check if the underlying channel is closed *)valread:t->'aIrmin.Type.t->'aError.resultLwt.t(** Read the next message *)valwrite:t->'aIrmin.Type.t->'a->unitLwt.t(** Write a message *)valok:t->unitLwt.t(** Send "OK" message with [unit] response *)valerr:t->string->unitLwt.t(** Send error message *)moduleHandshake:sigmoduleV1:sigvalversion:stringvalfingerprint:(moduleIrmin.Generic_key.S)->stringvalsend:(moduleIrmin.Generic_key.S)->t->boolLwt.tvalcheck:(moduleIrmin.Generic_key.S)->t->boolLwt.tendendmoduleRequest:sigtypeheader={command:string}valv_header:command:string->headervalwrite_header:t->header->unitLwt.tvalread_header:t->headerLwt.tendmoduleResponse:sigtypeheader={status:int}valv_header:status:int->headervalwrite_header:t->header->unitLwt.tvalread_header:t->headerLwt.tvalis_error:header->boolvalget_error:t->header->stringoptionLwt.tendmoduleReturn:sigtypeconn=ttype'at={status:int;conn:conn}valmake:int->conn->'atLwt.tvalerr:conn->string->'atLwt.tvalwrite:'aIrmin.Type.t->'a->'at->'atLwt.tvalv:conn->'aIrmin.Type.t->'a->'atLwt.tvalok:conn->unittLwt.tvalresult:conn->'aIrmin.Type.t->('a,[`Msgofstring])Result.t->'atLwt.tvalfinish:'at->unitLwt.tendendmoduletypeSigs=sigmoduleCodec:sigmoduletypeS=Codec.SmoduleBin:SmoduleJson:SendmoduletypeS=SmoduletypeIO=IOmoduleMake(IO:IO)(C:Codec.S):SwithmoduleIO=IOend