summaryrefslogtreecommitdiff
path: root/Presence/SocketLike.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-27 21:03:24 -0400
committerjoe <joe@jerkface.net>2013-06-27 21:03:24 -0400
commit81497b84304f33e814323c2d7d7a1640c05e3e18 (patch)
tree0ead1094d1fc3cac86f1e5150d90ba3d99f92fce /Presence/SocketLike.hs
parent549122c19409bc6b8e626b810e8738d2279bf20a (diff)
ServerC module provides a conduits interface for doServer
Diffstat (limited to 'Presence/SocketLike.hs')
-rw-r--r--Presence/SocketLike.hs38
1 files changed, 38 insertions, 0 deletions
diff --git a/Presence/SocketLike.hs b/Presence/SocketLike.hs
new file mode 100644
index 00000000..12fa07a3
--- /dev/null
+++ b/Presence/SocketLike.hs
@@ -0,0 +1,38 @@
1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2module SocketLike
3 ( SocketLike
4 , getSocketName
5 , getPeerName
6 , getPeerCred
7 , socketPort
8 , RestrictedSocket
9 , restrictSocket
10 , PortNumber
11 , SockAddr
12 , CUInt
13 ) where
14
15import Network.Socket
16 ( PortNumber
17 , SockAddr
18 )
19import Foreign.C.Types ( CUInt )
20
21import qualified Network.Socket as NS
22
23class SocketLike sock where
24 getSocketName :: sock -> IO SockAddr
25 getPeerName :: sock -> IO SockAddr
26 getPeerCred :: sock -> IO (CUInt, CUInt, CUInt)
27 socketPort :: sock -> IO PortNumber
28
29instance SocketLike NS.Socket where
30 getSocketName = NS.getSocketName
31 getPeerName = NS.getPeerName
32 getPeerCred = NS.getPeerCred
33 socketPort = NS.socketPort
34
35newtype RestrictedSocket = Restricted NS.Socket deriving SocketLike
36
37restrictSocket :: NS.Socket -> RestrictedSocket
38restrictSocket socket = Restricted socket