diff options
Diffstat (limited to 'Presence/SocketLike.hs')
-rw-r--r-- | Presence/SocketLike.hs | 38 |
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 #-} | ||
2 | module SocketLike | ||
3 | ( SocketLike | ||
4 | , getSocketName | ||
5 | , getPeerName | ||
6 | , getPeerCred | ||
7 | , socketPort | ||
8 | , RestrictedSocket | ||
9 | , restrictSocket | ||
10 | , PortNumber | ||
11 | , SockAddr | ||
12 | , CUInt | ||
13 | ) where | ||
14 | |||
15 | import Network.Socket | ||
16 | ( PortNumber | ||
17 | , SockAddr | ||
18 | ) | ||
19 | import Foreign.C.Types ( CUInt ) | ||
20 | |||
21 | import qualified Network.Socket as NS | ||
22 | |||
23 | class 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 | |||
29 | instance SocketLike NS.Socket where | ||
30 | getSocketName = NS.getSocketName | ||
31 | getPeerName = NS.getPeerName | ||
32 | getPeerCred = NS.getPeerCred | ||
33 | socketPort = NS.socketPort | ||
34 | |||
35 | newtype RestrictedSocket = Restricted NS.Socket deriving SocketLike | ||
36 | |||
37 | restrictSocket :: NS.Socket -> RestrictedSocket | ||
38 | restrictSocket socket = Restricted socket | ||