summaryrefslogtreecommitdiff
path: root/Presence/SocketLike.hs
diff options
context:
space:
mode:
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