summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/SocketLike.hs22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/Network/SocketLike.hs b/src/Network/SocketLike.hs
index 2aa78e3e..d533dd7f 100644
--- a/src/Network/SocketLike.hs
+++ b/src/Network/SocketLike.hs
@@ -1,4 +1,5 @@
1{-# LANGUAGE GeneralizedNewtypeDeriving #-} 1{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE CPP #-}
2-- | 3-- |
3-- 4--
4-- A socket could be used indirectly via a 'System.IO.Handle' or a conduit from 5-- A socket could be used indirectly via a 'System.IO.Handle' or a conduit from
@@ -68,14 +69,24 @@ instance SocketLike NS.Socket where
68 getPeerName = NS.getPeerName 69 getPeerName = NS.getPeerName
69 getPeerCred = NS.getPeerCred 70 getPeerCred = NS.getPeerCred
70 socketPort = NS.socketPort 71 socketPort = NS.socketPort
72#if MIN_VERSION_network(2,4,0)
73 sIsConnected = NS.isConnected -- warning: this is always False if the socket
74 -- was converted to a Handle
75 sIsBound = NS.isBound
76 sIsListening = NS.isListening
77 sIsReadable = NS.isReadable
78 sIsWritable = NS.isWritable
79 sClose = NS.close
80#else
71 sIsConnected = NS.sIsConnected -- warning: this is always False if the socket 81 sIsConnected = NS.sIsConnected -- warning: this is always False if the socket
72 -- was converted to a Handle 82 -- was converted to a Handle
73 sIsBound = NS.sIsBound 83 sIsBound = NS.sIsBound
74 sIsListening = NS.sIsListening 84 sIsListening = NS.sIsListening
75 sIsReadable = NS.sIsReadable 85 sIsReadable = NS.sIsReadable
76 sIsWritable = NS.sIsWritable 86 sIsWritable = NS.sIsWritable
77
78 sClose = NS.sClose 87 sClose = NS.sClose
88#endif
89
79 90
80-- | An encapsulated socket. Data reads and writes are not possible. 91-- | An encapsulated socket. Data reads and writes are not possible.
81data RestrictedSocket = Restricted (Maybe Handle) NS.Socket deriving Show 92data RestrictedSocket = Restricted (Maybe Handle) NS.Socket deriving Show
@@ -85,12 +96,21 @@ instance SocketLike RestrictedSocket where
85 getPeerName (Restricted mb sock) = NS.getPeerName sock 96 getPeerName (Restricted mb sock) = NS.getPeerName sock
86 getPeerCred (Restricted mb sock) = NS.getPeerCred sock 97 getPeerCred (Restricted mb sock) = NS.getPeerCred sock
87 socketPort (Restricted mb sock) = NS.socketPort sock 98 socketPort (Restricted mb sock) = NS.socketPort sock
99#if MIN_VERSION_network(2,4,0)
100 sIsConnected (Restricted mb sock) = maybe (NS.isConnected sock) (hIsOpen) mb
101 sIsBound (Restricted mb sock) = NS.isBound sock
102 sIsListening (Restricted mb sock) = NS.isListening sock
103 sIsReadable (Restricted mb sock) = NS.isReadable sock
104 sIsWritable (Restricted mb sock) = NS.isWritable sock
105 sClose (Restricted mb sock) = maybe (NS.close sock) (\h -> hClose h >> NS.close sock) mb
106#else
88 sIsConnected (Restricted mb sock) = maybe (NS.sIsConnected sock) (hIsOpen) mb 107 sIsConnected (Restricted mb sock) = maybe (NS.sIsConnected sock) (hIsOpen) mb
89 sIsBound (Restricted mb sock) = NS.sIsBound sock 108 sIsBound (Restricted mb sock) = NS.sIsBound sock
90 sIsListening (Restricted mb sock) = NS.sIsListening sock 109 sIsListening (Restricted mb sock) = NS.sIsListening sock
91 sIsReadable (Restricted mb sock) = NS.sIsReadable sock 110 sIsReadable (Restricted mb sock) = NS.sIsReadable sock
92 sIsWritable (Restricted mb sock) = NS.sIsWritable sock 111 sIsWritable (Restricted mb sock) = NS.sIsWritable sock
93 sClose (Restricted mb sock) = maybe (NS.sClose sock) (\h -> hClose h >> NS.sClose sock) mb 112 sClose (Restricted mb sock) = maybe (NS.sClose sock) (\h -> hClose h >> NS.sClose sock) mb
113#endif
94 114
95-- | Create a 'RestrictedSocket' that explicitly disallows sending or 115-- | Create a 'RestrictedSocket' that explicitly disallows sending or
96-- receiving data. 116-- receiving data.