Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file state.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181let(<.>)fgx=f(gx)type('a,'err)t=|Readof{buffer:bytes;off:int;len:int;k:int->('a,'err)t;eof:unit->('a,'err)t;}|Writeof{buffer:string;off:int;len:int;k:int->('a,'err)t}|Returnof'a|Errorof'errmoduletypeCONTEXT=sigtypettypeencodertypedecodervalpp:Capability.tFmt.t->tFmt.tvalencoder:t->encodervaldecoder:t->decoderendmoduletypeVALUE=sigtype'asendtype'arecvtypeerrortypeencodertypedecodervalencode:encoder->'asend->'a->(unit,error)tvaldecode:decoder->'arecv->('a,error)tendmoduleContext=structtypecapabilities={my_caps:Capability.tlist;their_caps:Capability.tlist;}typet={encoder:Pkt_line.Encoder.encoder;decoder:Pkt_line.Decoder.decoder;mutablecapabilities:capabilities;}typeencoder=Pkt_line.Encoder.encodertypedecoder=Pkt_line.Decoder.decoderletpp_pp_ctx_ppf_t=()letmake~my_caps=letcapabilities={my_caps;their_caps=[]}in{encoder=Pkt_line.Encoder.create();decoder=Pkt_line.Decoder.create();capabilities;}letwith_decoder~my_capsdecoder={encoder=Pkt_line.Encoder.create();decoder;capabilities={my_caps;their_caps=[]};}letencoder{encoder;_}=encoderletdecoder{decoder;_}=decoderletcapabilities{capabilities;_}=capabilitiesletreplace_their_capsctxtheir_caps=ctx.capabilities<-{ctx.capabilitieswiththeir_caps}letis_cap_shared{capabilities={my_caps;their_caps};_}cap=letis_cap_incaps=List.exists(func->Capability.equalccap)capsinis_cap_inmy_caps&&is_cap_intheir_capsendmoduleScheduler(Context:CONTEXT)(Value:VALUEwithtypeencoder=Context.encoderandtypedecoder=Context.decoder)=structtypeerror=Value.errorletbind:('a,'err)t->f:('a->('b,'err)t)->('b,'err)t=letrecbind'm~f=matchmwith|Returnv->fv|Error_aserr->err|Read({k;eof;_}asrd)->Read{rdwithk=bind'~f<.>k;eof=bind'~f<.>eof}|Write({k;_}aswr)->Write{wrwithk=bind'~f<.>k}inbind'letreturnv=Returnvletfailerror=Errorerrorletmapm~f=bindm~f:(funv->return(fv))let(>>=)mf=bindm~flet(>|=)mf=mapm~flet(let*)mf=m>>=flet(let+)mf=m>|=fletreword_errorfx=letrecmap_error=function|Return_asr->r|Errorerr->Error(ferr)|Read({k;eof;_}asrd)->Read{rdwithk=map_error<.>k;eof=map_error<.>eof}|Write({k;_}aswr)->Write{wrwithk=map_error<.>k}inmap_errorx(* Is slightly different from [m |> reword_error ~f >>= f1].
The places where [apply] used currently the alternative code above would be sufficient,
but that would end up in twice the number of function calls *)letapplym~bind_ret~bind_err=letrecapply'=function|Returnr->bind_retr|Errorerr->bind_errerr|Read({k;eof;_}asrd)->Read{rdwithk=apply'<.>k;eof=apply'<.>eof}|Write({k;_}aswr)->Write{wrwithk=apply'<.>k}inapply'mletencode:typea.Context.t->aValue.send->a->(Context.t->('b,[>`Protocoloferror])t)->('b,[>`Protocoloferror])t=functxwvk->letencoder=Context.encoderctxinValue.encodeencoderwv|>apply~bind_ret:(fun()->kctx)~bind_err:(funerr->Error(`Protocolerr))letsend:typea.Context.t->aValue.send->a->(unit,[>`Protocoloferror])t=functxwx->encodectxwx(fun_ctx->Return())letdecode:typea.Context.t->aValue.recv->(Context.t->a->('b,[>`Protocoloferror])t)->('b,[>`Protocoloferror])t=functxwk->letdecoder=Context.decoderctxinValue.decodedecoderw|>apply~bind_ret:(funv->kctxv)~bind_err:(fune->Error(`Protocole))letrecv:typea.Context.t->aValue.recv->(a,[>`Protocoloferror])t=functxw->decodectxw(fun_ctxv->Returnv)leterror_msgffmt=Fmt.kstr(funerr->Error(`Msgerr))fmtmoduleInfix=structlet(>>=)=(>>=)let(>|=)=(>|=)letreturn=returnletfail=failendmoduleSyntax=structlet(let*)=(let*)let(let+)=(let+)letreturn=returnletfail=failendend