summaryrefslogtreecommitdiff
path: root/dht/src/Network/SocketLike.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2019-10-16 06:29:03 +0000
committerJoe Crayne <joe@jerkface.net>2020-01-01 19:40:41 -0500
commitc4dcf8374e218e741f4c3120d889c420d8ca2edb (patch)
tree889a08628dd6769f55f88e56f40ed0d943e34622 /dht/src/Network/SocketLike.hs
parentf1cbe4adc0ea607d92e29086a8c3af7c89f85bee (diff)
Preparation for support of new network package:
* The network-bsd flag is split into two flags: - old-network-bsd (for network >2.6 && < 2.9) - new-network-bsd (for network >=3.0) * Unused methods in SocketLike class have been removed
Diffstat (limited to 'dht/src/Network/SocketLike.hs')
-rw-r--r--dht/src/Network/SocketLike.hs42
1 files changed, 2 insertions, 40 deletions
diff --git a/dht/src/Network/SocketLike.hs b/dht/src/Network/SocketLike.hs
index d533dd7f..27f6f492 100644
--- a/dht/src/Network/SocketLike.hs
+++ b/dht/src/Network/SocketLike.hs
@@ -44,50 +44,23 @@ class SocketLike sock where
44 getPeerName :: sock -> IO SockAddr 44 getPeerName :: sock -> IO SockAddr
45 -- | See 'NS.getPeerCred' 45 -- | See 'NS.getPeerCred'
46 getPeerCred :: sock -> IO (CUInt, CUInt, CUInt) 46 getPeerCred :: sock -> IO (CUInt, CUInt, CUInt)
47 -- | See 'NS.socketPort' 47
48 socketPort :: sock -> IO PortNumber 48 -- | Is the socket still valid? Connected
49 -- | See 'NS.sIsConnected'
50 --
51 -- __Warning__: Don't rely on this method if it's possible the socket was
52 -- converted into a 'Handle'.
53 sIsConnected :: sock -> IO Bool 49 sIsConnected :: sock -> IO Bool
54 -- | See 'NS.sIsBound'
55 sIsBound :: sock -> IO Bool
56 -- | See 'NS.sIsListening'
57 sIsListening :: sock -> IO Bool
58 -- | See 'NS.sIsReadable'
59 sIsReadable :: sock -> IO Bool
60 -- | See 'NS.sIsWritable'
61 sIsWritable :: sock -> IO Bool
62 50
63 -- | This is the only exposed write-access method to the
64 -- underlying state. Usually implemented by 'NS.close'
65 sClose :: sock -> IO ()
66 51
67instance SocketLike NS.Socket where 52instance SocketLike NS.Socket where
68 getSocketName = NS.getSocketName 53 getSocketName = NS.getSocketName
69 getPeerName = NS.getPeerName 54 getPeerName = NS.getPeerName
70 getPeerCred = NS.getPeerCred 55 getPeerCred = NS.getPeerCred
71 socketPort = NS.socketPort
72#if MIN_VERSION_network(2,4,0) 56#if MIN_VERSION_network(2,4,0)
73 sIsConnected = NS.isConnected -- warning: this is always False if the socket 57 sIsConnected = NS.isConnected -- warning: this is always False if the socket
74 -- was converted to a Handle 58 -- 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 59#else
81 sIsConnected = NS.sIsConnected -- warning: this is always False if the socket 60 sIsConnected = NS.sIsConnected -- warning: this is always False if the socket
82 -- was converted to a Handle 61 -- was converted to a Handle
83 sIsBound = NS.sIsBound
84 sIsListening = NS.sIsListening
85 sIsReadable = NS.sIsReadable
86 sIsWritable = NS.sIsWritable
87 sClose = NS.sClose
88#endif 62#endif
89 63
90
91-- | An encapsulated socket. Data reads and writes are not possible. 64-- | An encapsulated socket. Data reads and writes are not possible.
92data RestrictedSocket = Restricted (Maybe Handle) NS.Socket deriving Show 65data RestrictedSocket = Restricted (Maybe Handle) NS.Socket deriving Show
93 66
@@ -95,21 +68,10 @@ instance SocketLike RestrictedSocket where
95 getSocketName (Restricted mb sock) = NS.getSocketName sock 68 getSocketName (Restricted mb sock) = NS.getSocketName sock
96 getPeerName (Restricted mb sock) = NS.getPeerName sock 69 getPeerName (Restricted mb sock) = NS.getPeerName sock
97 getPeerCred (Restricted mb sock) = NS.getPeerCred sock 70 getPeerCred (Restricted mb sock) = NS.getPeerCred sock
98 socketPort (Restricted mb sock) = NS.socketPort sock
99#if MIN_VERSION_network(2,4,0) 71#if MIN_VERSION_network(2,4,0)
100 sIsConnected (Restricted mb sock) = maybe (NS.isConnected sock) (hIsOpen) mb 72 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 73#else
107 sIsConnected (Restricted mb sock) = maybe (NS.sIsConnected sock) (hIsOpen) mb 74 sIsConnected (Restricted mb sock) = maybe (NS.sIsConnected sock) (hIsOpen) mb
108 sIsBound (Restricted mb sock) = NS.sIsBound sock
109 sIsListening (Restricted mb sock) = NS.sIsListening sock
110 sIsReadable (Restricted mb sock) = NS.sIsReadable sock
111 sIsWritable (Restricted mb sock) = NS.sIsWritable sock
112 sClose (Restricted mb sock) = maybe (NS.sClose sock) (\h -> hClose h >> NS.sClose sock) mb
113#endif 75#endif
114 76
115-- | Create a 'RestrictedSocket' that explicitly disallows sending or 77-- | Create a 'RestrictedSocket' that explicitly disallows sending or