123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051(*
* Copyright (c) 2014 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.
*)openLwt.Infixletsrc=Logs.Src.create"tcpip-stack-socket"~doc:"Platform's native TCP/IP stack"moduleLog=(valLogs.src_logsrc:Logs.LOG)moduleV4V6=structmoduleTCP=Tcpv4v6_socketmoduleUDP=Udpv4v6_socketmoduleIP=Ipv4v6_sockettypet={udp:UDP.t;tcp:TCP.t;stop:unitLwt.u;switched_off:unitLwt.t;}letudp{udp;_}=udplettcp{tcp;_}=tcpletip_=()letlistent=t.switched_offletconnectudptcp=Log.info(funf->f"Dual IPv4 and IPv6 socket stack: connect");letswitched_off,stop=Lwt.wait()inUDP.set_switched_offudpswitched_off;TCP.set_switched_offtcpswitched_off;Lwt.return{tcp;udp;stop;switched_off}letdisconnectt=TCP.disconnectt.tcp>>=fun()->UDP.disconnectt.udp>|=fun()->Lwt.wakeup_latert.stop()end