123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960openFunctoria.DSLopenIpopenMclockopenMiscopenRandomopenTimeopenFunctoria.Actiontype'atcp=TCPtypetcpv4v6=v4v6tcplettcp=Functoria.Type.TypeTCPlettcpv4v6:tcpv4v6typ=tcp(* this needs to be a function due to the value restriction. *)lettcp_direct_func()=letpackages_v=right_tcpip_library~sublibs:["tcp"]"tcpip"inletconnect_modname=function|[ip;_time;_clock;_random]->code~pos:__POS__"%s.connect %s"modnameip|_->connect_err"tcp"4inimpl~packages_v~connect"Tcp.Flow.Make"(ip@->time@->mclock@->random@->tcp)letdirect_tcp?(mclock=default_monotonic_clock)?(time=default_time)?(random=default_random)ip=tcp_direct_func()$ip$time$mclock$randomlettcpv4v6_socket_conf~ipv4_only~ipv6_onlyipv4_keyipv6_key=letv=Runtime_arg.vinletruntime_args=[vipv4_only;vipv6_only;vipv4_key;vipv6_key]inletpackages_v=right_tcpip_library~sublibs:["tcpv4v6-socket"]"tcpip"inletconfigurei=matchget_targetiwith|`Unix|`MacOSX->ok()|_->error"TCPv4v6 socket not supported on non-UNIX targets."inletconnect_modname=function|[ipv4_only;ipv6_only;ipv4_key;ipv6_key]->code~pos:__POS__"%s.connect ~ipv4_only:%s ~ipv6_only:%s %s %s"modnameipv4_onlyipv6_onlyipv4_keyipv6_key|_->connect_err"tcpv4v6_socket_conf"4inimpl~packages_v~configure~runtime_args~connect"Tcpv4v6_socket"tcpv4v6letsocket_tcpv4v6?groupipv4ipv6=letipv4=matchipv4with|None->Ipaddr.V4.Prefix.global|Someip->Ipaddr.V4.Prefix.make32ipandipv6=matchipv6with|None->None|Someip->Some(Ipaddr.V6.Prefix.make128ip)andipv4_only=Runtime_arg.ipv4_only?group()andipv6_only=Runtime_arg.ipv6_only?group()intcpv4v6_socket_conf~ipv4_only~ipv6_only(Runtime_arg.V4.network?groupipv4)(Runtime_arg.V6.network?groupipv6)