summaryrefslogtreecommitdiff
path: root/dht
diff options
context:
space:
mode:
Diffstat (limited to 'dht')
-rw-r--r--dht/dht-client.cabal22
-rw-r--r--dht/src/Network/SocketLike.hs42
2 files changed, 19 insertions, 45 deletions
diff --git a/dht/dht-client.cabal b/dht/dht-client.cabal
index 3a513280..3569c6dd 100644
--- a/dht/dht-client.cabal
+++ b/dht/dht-client.cabal
@@ -32,10 +32,17 @@ flag network-uri
32 description: Use network-uri package. 32 description: Use network-uri package.
33 default: True 33 default: True
34 34
35flag network-bsd 35-- supports network-2.7, 2.8, with deprecation warnings
36flag old-network-bsd
36 description: Use network-bsd package. 37 description: Use network-bsd package.
37 default: True 38 default: True
38 39
40-- TODO: Due to removed functions, this flag doesn't actually build.
41-- In the future, this flag should support network >3.0
42flag new-network-bsd
43 description: Use newer network-bsd package.
44 default: False
45
39flag builder 46flag builder
40 description: Use older bytestring package and bytestring-builder. 47 description: Use older bytestring package and bytestring-builder.
41 default: False 48 default: False
@@ -223,11 +230,16 @@ library
223 if impl(ghc < 8) 230 if impl(ghc < 8)
224 Build-depends: transformers 231 Build-depends: transformers
225 232
226 if flag(network-bsd) 233 if flag(old-network-bsd)
227 Build-depends: network >= 3.0 234 Build-depends: network < 3.0
228 , network-uri >= 2.6 235 , network-uri >= 2.6
229 , network-bsd 236 , network-bsd < 2.8.1.0
230 else 237 else
238 if flag(new-network-bsd)
239 Build-depends: network >= 3.0
240 , network-uri >= 2.6
241 , network-bsd >= 2.8.1.0
242 else
231 if flag(network-uri) 243 if flag(network-uri)
232 Build-depends: network >= 2.6 && < 3.0 244 Build-depends: network >= 2.6 && < 3.0
233 , network-uri >= 2.6 245 , network-uri >= 2.6
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