Debian Codegraph @

Sound/Osc/Transport/Fd/Socket.hs

raw symbols SCIP
1 -- | Osc over Udp/Tcp implementation.
2 module Sound.Osc.Transport.Fd.Socket where
3
4 import qualified Sound.Osc.Transport.Fd as Fd {- hosc -}
5 import qualified Sound.Osc.Transport.Fd.Tcp as Fd.Tcp {- hosc -}
6 import qualified Sound.Osc.Transport.Fd.Udp as Fd.Udp {- hosc -}
7
8 -- | Protocol, either Udp or Tcp
9 data OscProtocol = Udp | Tcp
10 deriving (Eq, Read, Show)
11
12 -- | Hostname
13 type OscHostname = String
14
15 -- | Port number
16 type OscPort = Int
17
18 -- | Socket address
19 type OscSocketAddress = (OscProtocol, OscHostname, OscPort)
20
21 -- | Socket
22 data OscSocket = OscUdpSocket Fd.Udp.Udp | OscTcpSocket Fd.Tcp.Tcp
23
24 -- | Open socket at address
25 openOscSocket :: OscSocketAddress -> IO OscSocket
26 openOscSocket address =
27 case address of
28 (Tcp, hostname, port) -> fmap OscTcpSocket (Fd.Tcp.openTcp hostname port)
29 (Udp, hostname, port) -> fmap OscUdpSocket (Fd.Udp.openUdp hostname port)
30
31 -- | 'OscSocket' is an instance of 'Fd.Transport'.
32 instance Fd.Transport OscSocket where
33 sendPacket (OscTcpSocket fd) = Fd.Tcp.tcp_send_packet fd
34 sendPacket (OscUdpSocket fd) = Fd.Udp.udp_send_packet fd
35 recvPacket (OscTcpSocket fd) = Fd.Tcp.tcp_recv_packet fd
36 recvPacket (OscUdpSocket fd) = Fd.Udp.udp_recv_packet fd
37 recvPacketOr (OscTcpSocket fd) = Fd.Tcp.tcp_recv_packet_or fd
38 recvPacketOr (OscUdpSocket fd) = Fd.Udp.udp_recv_packet_or fd
39 close (OscTcpSocket fd) = Fd.Tcp.tcp_close fd
40 close (OscUdpSocket fd) = Fd.Udp.udp_close fd