1
1
{-# LANGUAGE RebindableSyntax, TemplateHaskell #-}
2
+ {-# LANGUAGE BangPatterns #-}
2
3
{-# OPTIONS_GHC -fno-warn-orphans #-}
3
4
module Main where
4
5
@@ -111,7 +112,7 @@ testEarlyDisconnect = do
111
112
server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
112
113
server serverAddr clientAddr serverDone = do
113
114
tlog " Server"
114
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
115
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
115
116
Right endpoint <- newEndPoint transport
116
117
putMVar serverAddr (address endpoint)
117
118
theirAddr <- readMVar clientAddr
@@ -216,7 +217,7 @@ testEarlyCloseSocket = do
216
217
server :: MVar EndPointAddress -> MVar EndPointAddress -> MVar () -> IO ()
217
218
server serverAddr clientAddr serverDone = do
218
219
tlog " Server"
219
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
220
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
220
221
Right endpoint <- newEndPoint transport
221
222
putMVar serverAddr (address endpoint)
222
223
theirAddr <- readMVar clientAddr
@@ -324,13 +325,13 @@ testEarlyCloseSocket = do
324
325
-- | Test the creation of a transport with an invalid address
325
326
testInvalidAddress :: IO ()
326
327
testInvalidAddress = do
327
- Left _ <- createTransport " invalidHostName" " 0" defaultTCPParameters
328
+ Left _ <- createTransport " invalidHostName" " 0" ((,) " invalidHostName " ) defaultTCPParameters
328
329
return ()
329
330
330
331
-- | Test connecting to invalid or non-existing endpoints
331
332
testInvalidConnect :: IO ()
332
333
testInvalidConnect = do
333
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
334
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
334
335
Right endpoint <- newEndPoint transport
335
336
336
337
-- Syntax error in the endpoint address
@@ -361,7 +362,7 @@ testIgnoreCloseSocket = do
361
362
clientDone <- newEmptyMVar
362
363
serverDone <- newEmptyMVar
363
364
connectionEstablished <- newEmptyMVar
364
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
365
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
365
366
366
367
-- Server
367
368
forkTry $ do
@@ -451,7 +452,7 @@ testBlockAfterCloseSocket = do
451
452
clientDone <- newEmptyMVar
452
453
serverDone <- newEmptyMVar
453
454
connectionEstablished <- newEmptyMVar
454
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
455
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
455
456
456
457
-- Server
457
458
forkTry $ do
@@ -531,7 +532,7 @@ testUnnecessaryConnect numThreads = do
531
532
serverAddr <- newEmptyMVar
532
533
533
534
forkTry $ do
534
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
535
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
535
536
Right endpoint <- newEndPoint transport
536
537
putMVar serverAddr (address endpoint)
537
538
@@ -570,11 +571,11 @@ testUnnecessaryConnect numThreads = do
570
571
-- | Test that we can create "many" transport instances
571
572
testMany :: IO ()
572
573
testMany = do
573
- Right masterTransport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
574
+ Right masterTransport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
574
575
Right masterEndPoint <- newEndPoint masterTransport
575
576
576
577
replicateM_ 10 $ do
577
- mTransport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
578
+ mTransport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
578
579
case mTransport of
579
580
Left ex -> do
580
581
putStrLn $ " IOException: " ++ show ex ++ " ; errno = " ++ show (ioe_errno ex)
@@ -591,7 +592,7 @@ testMany = do
591
592
-- | Test what happens when the transport breaks completely
592
593
testBreakTransport :: IO ()
593
594
testBreakTransport = do
594
- Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" defaultTCPParameters
595
+ Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
595
596
Right endpoint <- newEndPoint transport
596
597
597
598
killThread (transportThread internals) -- Uh oh
@@ -647,7 +648,7 @@ testReconnect = do
647
648
648
649
-- Client
649
650
forkTry $ do
650
- Right transport <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
651
+ Right transport <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
651
652
Right endpoint <- newEndPoint transport
652
653
let theirAddr = encodeEndPointAddress " 127.0.0.1" serverPort 0
653
654
@@ -723,7 +724,7 @@ testUnidirectionalError = do
723
724
724
725
-- Client
725
726
forkTry $ do
726
- Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" defaultTCPParameters
727
+ Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
727
728
Right endpoint <- newEndPoint transport
728
729
let theirAddr = encodeEndPointAddress " 127.0.0.1" serverPort 0
729
730
@@ -778,7 +779,7 @@ testUnidirectionalError = do
778
779
779
780
testInvalidCloseConnection :: IO ()
780
781
testInvalidCloseConnection = do
781
- Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" defaultTCPParameters
782
+ Right (transport, internals) <- createTransportExposeInternals " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
782
783
serverAddr <- newEmptyMVar
783
784
clientDone <- newEmptyMVar
784
785
serverDone <- newEmptyMVar
@@ -820,9 +821,10 @@ testUseRandomPort :: IO ()
820
821
testUseRandomPort = do
821
822
testDone <- newEmptyMVar
822
823
forkTry $ do
823
- Right transport1 <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
824
+ Right transport1 <- createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters
824
825
Right ep1 <- newEndPoint transport1
825
- Right transport2 <- createTransport " 127.0.0.1" " 0" defaultTCPParameters
826
+ -- Same as transport1, but is strict in the port.
827
+ Right transport2 <- createTransport " 127.0.0.1" " 0" (\ (! port) -> (" 127.0.0.1" , port)) defaultTCPParameters
826
828
Right ep2 <- newEndPoint transport2
827
829
Right conn1 <- connect ep2 (address ep1) ReliableOrdered defaultConnectHints
828
830
ConnectionOpened _ _ _ <- receive ep1
@@ -848,7 +850,7 @@ main = do
848
850
]
849
851
-- Run the generic tests even if the TCP specific tests failed..
850
852
testTransport (either (Left . show ) (Right ) <$>
851
- createTransport " 127.0.0.1" " 0" defaultTCPParameters)
853
+ createTransport " 127.0.0.1" " 0" ((,) " 127.0.0.1 " ) defaultTCPParameters)
852
854
-- ..but if the generic tests pass, still fail if the specific tests did not
853
855
case tcpResult of
854
856
Left err -> throwIO err
0 commit comments