Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 4014905

Browse files
Move to network 3.
1 parent 6fe2aab commit 4014905

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

ChangeLog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
next release
22

3-
*
3+
* Move to network 3.
44

55
2019-12-31 FacundoDominguez <facundo.dominguez@tweag.io> 0.7.0
66

network-transport-tcp.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Library
3131
data-accessor >= 0.2 && < 0.3,
3232
containers >= 0.4 && < 0.7,
3333
bytestring >= 0.9 && < 0.11,
34-
network >= 2.6.2 && < 2.9,
34+
network >= 3.1 && < 3.2,
3535
uuid >= 1.3 && < 1.4
3636
Exposed-modules: Network.Transport.TCP,
3737
Network.Transport.TCP.Internal
@@ -51,7 +51,7 @@ Test-Suite TestTCP
5151
Build-Depends: base >= 4.3 && < 5,
5252
bytestring >= 0.9 && < 0.11,
5353
network-transport-tests >= 0.2.1.0 && < 0.3,
54-
network >= 2.3 && < 2.9,
54+
network >= 3.1 && < 3.2,
5555
network-transport,
5656
network-transport-tcp
5757
ghc-options: -threaded -rtsopts -with-rtsopts=-N

src/Network/Transport/TCP.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import qualified Network.Socket as N
8989
, ServiceName
9090
, Socket
9191
, getAddrInfo
92+
, maxListenQueue
9293
, socket
9394
, addrFamily
9495
, addrAddress
@@ -98,7 +99,6 @@ import qualified Network.Socket as N
9899
, SocketOption(ReuseAddr, NoDelay, UserTimeout, KeepAlive)
99100
, isSupportedSocketOption
100101
, connect
101-
, sOMAXCONN
102102
, AddrInfo
103103
, SockAddr(..)
104104
)
@@ -675,7 +675,7 @@ createTransportExposeInternals addr params = do
675675
-- | Default TCP parameters
676676
defaultTCPParameters :: TCPParameters
677677
defaultTCPParameters = TCPParameters {
678-
tcpBacklog = N.sOMAXCONN
678+
tcpBacklog = N.maxListenQueue
679679
, tcpReuseServerAddr = True
680680
, tcpReuseClientAddr = True
681681
, tcpNoDelay = False

src/Network/Transport/TCP/Internal.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ import qualified Network.Transport.TCP.Mock.Socket as N
4242
import qualified Network.Socket as N
4343
#endif
4444
( HostName
45+
, NameInfoFlag(NI_NUMERICHOST)
4546
, ServiceName
4647
, Socket
4748
, SocketType(Stream)
4849
, SocketOption(ReuseAddr)
4950
, getAddrInfo
5051
, defaultHints
5152
, socket
52-
, bindSocket
53+
, bind
5354
, listen
5455
, addrFamily
5556
, addrAddress
5657
, defaultProtocol
5758
, setSocketOption
5859
, accept
59-
, sClose
60+
, close
6061
, socketPort
6162
, shutdown
6263
, ShutdownCmd(ShutdownBoth)
6364
, SockAddr(..)
64-
, inet_ntoa
6565
, getNameInfo
6666
)
6767

@@ -235,13 +235,13 @@ forkServer host port backlog reuseAddr errorHandler terminationHandler requestHa
235235
bracketOnError (N.socket (N.addrFamily addr) N.Stream N.defaultProtocol)
236236
tryCloseSocket $ \sock -> do
237237
when reuseAddr $ N.setSocketOption sock N.ReuseAddr 1
238-
N.bindSocket sock (N.addrAddress addr)
238+
N.bind sock (N.addrAddress addr)
239239
N.listen sock backlog
240240

241241
-- Close up and fill the synchonizing MVar.
242242
let release :: ((N.Socket, N.SockAddr), MVar ()) -> IO ()
243243
release ((sock, _), socketClosed) =
244-
N.sClose sock `finally` putMVar socketClosed ()
244+
N.close sock `finally` putMVar socketClosed ()
245245

246246
-- Run the request handler.
247247
let act restore (sock, sockAddr) = do
@@ -263,7 +263,7 @@ forkServer host port backlog reuseAddr errorHandler terminationHandler requestHa
263263
-- Looks like 'act' will never throw an exception, but to be
264264
-- safe we'll close the socket if it does.
265265
let handler :: SomeException -> IO ()
266-
handler _ = N.sClose sock
266+
handler _ = N.close sock
267267
catch (act restore (sock, sockAddr)) handler
268268

269269
-- We start listening for incoming requests in a separate thread. When
@@ -296,7 +296,7 @@ recvWord32 = fmap (decodeWord32 . BS.concat) . flip recvExact 4
296296
-- | Close a socket, ignoring I/O exceptions.
297297
tryCloseSocket :: N.Socket -> IO ()
298298
tryCloseSocket sock = void . tryIO $
299-
N.sClose sock
299+
N.close sock
300300

301301
-- | Shutdown socket sends and receives, ignoring I/O exceptions.
302302
tryShutdownSocketBoth :: N.Socket -> IO ()
@@ -330,7 +330,7 @@ resolveSockAddr sockAddr = case sockAddr of
330330
(mResolvedHost, mResolvedPort) <- N.getNameInfo [] True False sockAddr
331331
case (mResolvedHost, mResolvedPort) of
332332
(Just resolvedHost, Nothing) -> do
333-
numericHost <- N.inet_ntoa host
333+
(Just numericHost, _) <- N.getNameInfo [N.NI_NUMERICHOST] True False sockAddr
334334
return $ Just (numericHost, resolvedHost, show port)
335335
_ -> error $ concat [
336336
"decodeSockAddr: unexpected resolution "

tests/TestTCP.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import qualified Network.Transport.TCP.Mock.Socket as N
6464
#else
6565
import qualified Network.Socket as N
6666
#endif
67-
( sClose
67+
( close
6868
, ServiceName
6969
, Socket
7070
, AddrInfo
@@ -199,7 +199,7 @@ testEarlyDisconnect = do
199199
sendMany sock (encodeWord32 10002 : prependLength ["pong"])
200200

201201
-- Close the socket
202-
N.sClose sock
202+
N.close sock
203203

204204
let ourAddress = encodeEndPointAddress "127.0.0.1" clientPort 0
205205
putMVar clientAddr ourAddress
@@ -215,7 +215,7 @@ testEarlyDisconnect = do
215215

216216
-- Close the socket without closing the connection explicitly
217217
-- The server should receive an error event
218-
N.sClose sock
218+
N.close sock
219219

220220
-- | Test the behaviour of a premature CloseSocket request
221221
testEarlyCloseSocket :: IO ()
@@ -316,7 +316,7 @@ testEarlyCloseSocket = do
316316
encodeWord32 (encodeControlHeader CloseSocket)
317317
, encodeWord32 1024
318318
]
319-
N.sClose sock
319+
N.close sock
320320

321321
let ourAddress = encodeEndPointAddress "127.0.0.1" clientPort 0
322322
putMVar clientAddr ourAddress
@@ -336,7 +336,7 @@ testEarlyCloseSocket = do
336336
encodeWord32 (encodeControlHeader CloseSocket)
337337
, encodeWord32 0
338338
]
339-
N.sClose sock
339+
N.close sock
340340

341341
-- | Test the creation of a transport with an invalid address
342342
testInvalidAddress :: IO ()
@@ -451,7 +451,7 @@ testIgnoreCloseSocket = do
451451
encodeWord32 (encodeControlHeader CloseSocket)
452452
, encodeWord32 1024
453453
]
454-
N.sClose sock
454+
N.close sock
455455

456456
putMVar clientDone ()
457457

@@ -576,9 +576,9 @@ testUnnecessaryConnect numThreads = do
576576
-- We might get either Invalid or Crossed (the transport does not
577577
-- maintain enough history to be able to tell)
578578
Right (_, sock, ConnectionRequestInvalid) ->
579-
N.sClose sock
579+
N.close sock
580580
Right (_, sock, ConnectionRequestCrossed) ->
581-
N.sClose sock
581+
N.close sock
582582
Left _ ->
583583
return ()
584584
putMVar done ()

0 commit comments

Comments
 (0)