@@ -10,6 +10,7 @@ import Network.Transport.TCP ( createTransport
10 , createTransportExposeInternals
10 , createTransportExposeInternals
11 , TransportInternals(..)
11 , TransportInternals(..)
12 , encodeEndPointAddress
12 , encodeEndPointAddress
13+ , defaultTCPParameters
14import Data.Int (Int32)
15import Data.Int (Int32)
15import Control.Concurrent (threadDelay, killThread)
16import Control.Concurrent (threadDelay, killThread)
@@ -82,7 +83,7 @@ testEarlyDisconnect nextPort = do
82 server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
83 server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
83 server serverAddr clientAddr serverDone = do
84 server serverAddr clientAddr serverDone = do
84 tlog "Server"
85 tlog "Server"
85− Right transport <- nextPort >>= createTransport "127.0.0.1"
86+ Right transport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
86 Right endpoint <- newEndPoint transport
87 Right endpoint <- newEndPoint transport
87 putMVar serverAddr (address endpoint)
88 putMVar serverAddr (address endpoint)
88 theirAddr <- readMVar clientAddr
89 theirAddr <- readMVar clientAddr
@@ -134,7 +135,7 @@ testEarlyDisconnect nextPort = do
134 putMVar clientAddr ourAddress
135 putMVar clientAddr ourAddress
136 -- Listen for incoming messages
137 -- Listen for incoming messages
137− forkServer "127.0.0.1" clientPort 5 throwIO $ \sock -> do
138+ forkServer "127.0.0.1" clientPort 5 True throwIO $ \sock -> do
138 -- Initial setup
139 -- Initial setup
139 0 <- recvInt32 sock :: IO Int
140 0 <- recvInt32 sock :: IO Int
140 _ <- recvWithLength sock
141 _ <- recvWithLength sock
@@ -160,7 +161,7 @@ testEarlyDisconnect nextPort = do
160 N.sClose sock
161 N.sClose sock
162 -- Connect to the server
163 -- Connect to the server
163− Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr defaultConnectHints
164+ Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr True Nothing
165 -- Request a new connection, but don't wait for the response
166 -- Request a new connection, but don't wait for the response
166 let reqId = 0 :: Int32
167 let reqId = 0 :: Int32
@@ -186,7 +187,7 @@ testEarlyCloseSocket nextPort = do
186 server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
187 server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
187 server serverAddr clientAddr serverDone = do
188 server serverAddr clientAddr serverDone = do
188 tlog "Server"
189 tlog "Server"
189− Right transport <- nextPort >>= createTransport "127.0.0.1"
190+ Right transport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
190 Right endpoint <- newEndPoint transport
191 Right endpoint <- newEndPoint transport
191 putMVar serverAddr (address endpoint)
192 putMVar serverAddr (address endpoint)
192 theirAddr <- readMVar clientAddr
193 theirAddr <- readMVar clientAddr
@@ -245,7 +246,7 @@ testEarlyCloseSocket nextPort = do
245 putMVar clientAddr ourAddress
246 putMVar clientAddr ourAddress
247 -- Listen for incoming messages
248 -- Listen for incoming messages
248− forkServer "127.0.0.1" clientPort 5 throwIO $ \sock -> do
249+ forkServer "127.0.0.1" clientPort 5 True throwIO $ \sock -> do
249 -- Initial setup
250 -- Initial setup
250 0 <- recvInt32 sock :: IO Int
251 0 <- recvInt32 sock :: IO Int
251 _ <- recvWithLength sock
252 _ <- recvWithLength sock
@@ -273,7 +274,7 @@ testEarlyCloseSocket nextPort = do
273 N.sClose sock
274 N.sClose sock
275 -- Connect to the server
276 -- Connect to the server
276− Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr defaultConnectHints
277+ Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr True Nothing
278 -- Request a new connection, but don't wait for the response
279 -- Request a new connection, but don't wait for the response
279 let reqId = 0 :: Int32
280 let reqId = 0 :: Int32
@@ -287,14 +288,14 @@ testEarlyCloseSocket nextPort = do
287-- | Test the creation of a transport with an invalid address
288-- | Test the creation of a transport with an invalid address
288testInvalidAddress :: IO N.ServiceName -> IO ()
289testInvalidAddress :: IO N.ServiceName -> IO ()
289testInvalidAddress nextPort = do
290testInvalidAddress nextPort = do
290− Left _ <- nextPort >>= createTransport "invalidHostName"
291+ Left _ <- nextPort >>= \port -> createTransport "invalidHostName" port defaultTCPParameters
291 return ()
292 return ()
293-- | Test connecting to invalid or non-existing endpoints
294-- | Test connecting to invalid or non-existing endpoints
294testInvalidConnect :: IO N.ServiceName -> IO ()
295testInvalidConnect :: IO N.ServiceName -> IO ()
295testInvalidConnect nextPort = do
296testInvalidConnect nextPort = do
296 port <- nextPort
297 port <- nextPort
297− Right transport <- createTransport "127.0.0.1" port
298+ Right transport <- createTransport "127.0.0.1" port defaultTCPParameters
298 Right endpoint <- newEndPoint transport
299 Right endpoint <- newEndPoint transport
300 -- Syntax error in the endpoint address
301 -- Syntax error in the endpoint address
@@ -322,7 +323,7 @@ testIgnoreCloseSocket :: IO N.ServiceName -> IO ()
322testIgnoreCloseSocket nextPort = do
323testIgnoreCloseSocket nextPort = do
323 serverAddr <- newEmptyMVar
324 serverAddr <- newEmptyMVar
324 clientDone <- newEmptyMVar
325 clientDone <- newEmptyMVar
325− Right transport <- nextPort >>= createTransport "127.0.0.1"
326+ Right transport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
327 forkTry $ server transport serverAddr
328 forkTry $ server transport serverAddr
328 forkTry $ client transport serverAddr clientDone
329 forkTry $ client transport serverAddr clientDone
@@ -360,7 +361,7 @@ testIgnoreCloseSocket nextPort = do
360 let ourAddress = address endpoint
361 let ourAddress = address endpoint
362 -- Connect to the server
363 -- Connect to the server
363− Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr defaultConnectHints
364+ Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr True Nothing
365 -- Request a new connection
366 -- Request a new connection
366 tlog "Requesting connection"
367 tlog "Requesting connection"
@@ -405,7 +406,7 @@ testBlockAfterCloseSocket nextPort = do
405 clientAddr <- newEmptyMVar
406 clientAddr <- newEmptyMVar
406 clientDone <- newEmptyMVar
407 clientDone <- newEmptyMVar
407 port <- nextPort
408 port <- nextPort
408− Right transport <- createTransport "127.0.0.1" port
409+ Right transport <- createTransport "127.0.0.1" port defaultTCPParameters
410 forkTry $ server transport serverAddr clientAddr
411 forkTry $ server transport serverAddr clientAddr
411 forkTry $ client transport serverAddr clientAddr clientDone
412 forkTry $ client transport serverAddr clientAddr clientDone
@@ -440,7 +441,7 @@ testBlockAfterCloseSocket nextPort = do
440 let ourAddress = address endpoint
441 let ourAddress = address endpoint
442 -- Connect to the server
443 -- Connect to the server
443− Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr defaultConnectHints
444+ Right (sock, ConnectionRequestAccepted) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr True Nothing
445 -- Request a new connection
446 -- Request a new connection
446 tlog "Requesting connection"
447 tlog "Requesting connection"
@@ -482,7 +483,7 @@ testUnnecessaryConnect nextPort numThreads = do
482 serverAddr <- newEmptyMVar
483 serverAddr <- newEmptyMVar
484 forkTry $ do
485 forkTry $ do
485− Right transport <- nextPort >>= createTransport "127.0.0.1"
486+ Right transport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
486 Right endpoint <- newEndPoint transport
487 Right endpoint <- newEndPoint transport
487 putMVar serverAddr (address endpoint)
488 putMVar serverAddr (address endpoint)
@@ -495,7 +496,7 @@ testUnnecessaryConnect nextPort numThreads = do
495 dones <- replicateM numThreads $ do
496 dones <- replicateM numThreads $ do
496 done <- newEmptyMVar
497 done <- newEmptyMVar
497 forkTry $ do
498 forkTry $ do
498− Right (_, reply) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr defaultConnectHints
499+ Right (_, reply) <- readMVar serverAddr >>= \addr -> socketToEndPoint ourAddress addr True Nothing
499 case reply of
500 case reply of
500 ConnectionRequestAccepted ->
501 ConnectionRequestAccepted ->
501 putMVar gotAccepted ()
502 putMVar gotAccepted ()
@@ -516,11 +517,11 @@ testUnnecessaryConnect nextPort numThreads = do
516-- | Test that we can create "many" transport instances
517-- | Test that we can create "many" transport instances
517testMany :: IO N.ServiceName -> IO ()
518testMany :: IO N.ServiceName -> IO ()
518testMany nextPort = do
519testMany nextPort = do
519− Right masterTransport <- nextPort >>= createTransport "127.0.0.1"
520+ Right masterTransport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
520 Right masterEndPoint <- newEndPoint masterTransport
521 Right masterEndPoint <- newEndPoint masterTransport
522 replicateM_ 10 $ do
523 replicateM_ 10 $ do
523− mTransport <- nextPort >>= createTransport "127.0.0.1"
524+ mTransport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
524 case mTransport of
525 case mTransport of
525 Left ex -> do
526 Left ex -> do
526 putStrLn $ "IOException: " ++ show ex ++ "; errno = " ++ show (ioe_errno ex)
527 putStrLn $ "IOException: " ++ show ex ++ "; errno = " ++ show (ioe_errno ex)
@@ -537,7 +538,7 @@ testMany nextPort = do
537-- | Test what happens when the transport breaks completely
538-- | Test what happens when the transport breaks completely
538testBreakTransport :: IO N.ServiceName -> IO ()
539testBreakTransport :: IO N.ServiceName -> IO ()
539testBreakTransport nextPort = do
540testBreakTransport nextPort = do
540− Right (transport, internals) <- nextPort >>= createTransportExposeInternals "127.0.0.1"
541+ Right (transport, internals) <- nextPort >>= \port -> createTransportExposeInternals "127.0.0.1" port defaultTCPParameters
541 Right endpoint <- newEndPoint transport
542 Right endpoint <- newEndPoint transport
543 killThread (transportThread internals) -- Uh oh
544 killThread (transportThread internals) -- Uh oh
@@ -567,7 +568,7 @@ testReconnect nextPort = do
568 counter <- newMVar (0 :: Int)
569 counter <- newMVar (0 :: Int)
570− forkServer "127.0.0.1" serverPort 5 throwIO $ \sock -> do
571+ forkServer "127.0.0.1" serverPort 5 True throwIO $ \sock -> do
571 -- Accept the connection
572 -- Accept the connection
572 Right 0 <- tryIO $ (recvInt32 sock :: IO Int)
573 Right 0 <- tryIO $ (recvInt32 sock :: IO Int)
573 Right _ <- tryIO $ recvWithLength sock
574 Right _ <- tryIO $ recvWithLength sock
@@ -596,7 +597,7 @@ testReconnect nextPort = do
597 -- Client
598 -- Client
598 forkTry $ do
599 forkTry $ do
599− Right transport <- nextPort >>= createTransport "127.0.0.1"
600+ Right transport <- nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters
600 Right endpoint <- newEndPoint transport
601 Right endpoint <- newEndPoint transport
601 let theirAddr = encodeEndPointAddress "127.0.0.1" serverPort 0
602 let theirAddr = encodeEndPointAddress "127.0.0.1" serverPort 0
@@ -642,7 +643,7 @@ testUnidirectionalError nextPort = do
642 serverGotPing <- newEmptyMVar
643 serverGotPing <- newEmptyMVar
644 -- Server
645 -- Server
645− forkServer "127.0.0.1" serverPort 5 throwIO $ \sock -> do
646+ forkServer "127.0.0.1" serverPort 5 True throwIO $ \sock -> do
646 -- We accept connections, but when an exception occurs we don't do
647 -- We accept connections, but when an exception occurs we don't do
647 -- anything (in particular, we don't close the socket). This is important
648 -- anything (in particular, we don't close the socket). This is important
648 -- because when we shutdown one direction of the socket a recv here will
649 -- because when we shutdown one direction of the socket a recv here will
@@ -663,7 +664,7 @@ testUnidirectionalError nextPort = do
664 -- Client
665 -- Client
665 forkTry $ do
666 forkTry $ do
666− Right (transport, internals) <- nextPort >>= createTransportExposeInternals "127.0.0.1"
667+ Right (transport, internals) <- nextPort >>= \port -> createTransportExposeInternals "127.0.0.1" port defaultTCPParameters
667 Right endpoint <- newEndPoint transport
668 Right endpoint <- newEndPoint transport
668 let theirAddr = encodeEndPointAddress "127.0.0.1" serverPort 0
669 let theirAddr = encodeEndPointAddress "127.0.0.1" serverPort 0
@@ -718,7 +719,7 @@ testUnidirectionalError nextPort = do
719testInvalidCloseConnection :: IO N.ServiceName -> IO ()
720testInvalidCloseConnection :: IO N.ServiceName -> IO ()
720testInvalidCloseConnection nextPort = do
721testInvalidCloseConnection nextPort = do
721− Right (transport, internals) <- nextPort >>= createTransportExposeInternals "127.0.0.1"
722+ Right (transport, internals) <- nextPort >>= \port -> createTransportExposeInternals "127.0.0.1" port defaultTCPParameters
722 serverAddr <- newEmptyMVar
723 serverAddr <- newEmptyMVar
723 clientDone <- newEmptyMVar
724 clientDone <- newEmptyMVar
724 serverDone <- newEmptyMVar
725 serverDone <- newEmptyMVar
@@ -773,7 +774,7 @@ main = do
773 , ("InvalidCloseConnection", testInvalidCloseConnection nextPort)
774 , ("InvalidCloseConnection", testInvalidCloseConnection nextPort)
775 -- Run the generic tests even if the TCP specific tests failed..
776 -- Run the generic tests even if the TCP specific tests failed..
776− testTransport (either (Left . show) (Right) <$> nextPort >>= createTransport "127.0.0.1")
777+ testTransport (either (Left . show) (Right) <$> nextPort >>= \port -> createTransport "127.0.0.1" port defaultTCPParameters)
777 -- ..but if the generic tests pass, still fail if the specific tests did
778 -- ..but if the generic tests pass, still fail if the specific tests did
778 case tcpResult of
779 case tcpResult of
779 Left err -> throwIO err
780 Left err -> throwIO err