Skip to content

Commit

Permalink
Merge pull request #65 from naushadh/relax-bound-network
Browse files Browse the repository at this point in the history
Add support for network-3.0.0.0
  • Loading branch information
gregorycollins authored Jan 28, 2019
2 parents 18735cc + 8ebb795 commit 1451ac7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ docs/templates/out
.cabal-sandbox/
cabal.sandbox.config
cabal.project.local
.stack-work/
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 1.5.0.2
Fix [stackage#4312](https://github.com/commercialhaskell/stackage/issues/4312): Relax `network` upper bound

# Version 1.5.0.1
Bugfix: `concurrentMerge []` should not block forever, even if this case is
pathological.
Expand Down
2 changes: 1 addition & 1 deletion io-streams.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: io-streams
Version: 1.5.0.1
Version: 1.5.0.2
License: BSD3
License-file: LICENSE
Category: Data, Network, IO-Streams
Expand Down
2 changes: 1 addition & 1 deletion test/System/IO/Streams/Tests/Concurrent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ testConcurrentMerge = testCase "concurrent/concurrentMerge" $ do
chans
inputs <- mapM Streams.chanToInput chans
resultMVar <- newEmptyMVar
forkIO (Streams.concurrentMerge inputs >>= Streams.toList
_ <- forkIO (Streams.concurrentMerge inputs >>= Streams.toList
>>= putMVar resultMVar)
putMVar firstMVar 0
result <- takeMVar resultMVar
Expand Down
34 changes: 26 additions & 8 deletions test/System/IO/Streams/Tests/Network.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}

module System.IO.Streams.Tests.Network (tests) where

Expand All @@ -13,6 +14,10 @@ import System.Timeout (timeout)
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.HUnit hiding (Test)
#if MIN_VERSION_network(2,7,0)
#else
import Data.List (intercalate)
#endif
------------------------------------------------------------------------------
import qualified System.IO.Streams.Internal as Streams
import qualified System.IO.Streams.Internal.Network as Streams
Expand All @@ -32,39 +37,52 @@ testSocket = testCase "network/socket" $
assertEqual "ok" (Just ()) x

where
-- compats
#if MIN_VERSION_network(2,7,0)
mkAddr = return . N.tupleToHostAddress
defaultPort = N.defaultPort
close = N.close
bind = N.bind
#else
mkAddr (o1,o2,o3,o4) = N.inet_addr . intercalate "." $ map show [o1,o2,o3,o4]
defaultPort = N.aNY_PORT
close = N.sClose
bind = N.bindSocket
#endif

go = do
portMVar <- newEmptyMVar
resultMVar <- newEmptyMVar
forkIO $ client portMVar resultMVar
_ <- forkIO $ client portMVar resultMVar
server portMVar
l <- takeMVar resultMVar
assertEqual "testSocket" l ["ok"]

client mvar resultMVar = do
port <- takeMVar mvar
sock <- N.socket N.AF_INET N.Stream N.defaultProtocol
addr <- N.inet_addr "127.0.0.1"
addr <- mkAddr (127, 0, 0, 1)
let saddr = N.SockAddrInet port addr
N.connect sock saddr
(is, os) <- Streams.socketToStreams sock
Streams.fromList ["", "ok"] >>= Streams.connectTo os
N.shutdown sock N.ShutdownSend
Streams.toList is >>= putMVar resultMVar
N.sClose sock
close sock

server mvar = do
sock <- N.socket N.AF_INET N.Stream N.defaultProtocol
addr <- N.inet_addr "127.0.0.1"
let saddr = N.SockAddrInet N.aNY_PORT addr
N.bindSocket sock saddr
addr <- mkAddr (127, 0, 0, 1)
let saddr = N.SockAddrInet defaultPort addr
bind sock saddr
N.listen sock 5
port <- N.socketPort sock
putMVar mvar port
(csock, _) <- N.accept sock
(is, os) <- Streams.socketToStreams csock
Streams.toList is >>= flip Streams.writeList os
N.sClose csock
N.sClose sock
close csock
close sock

testSocketWithError :: Test
testSocketWithError = testCase "network/socket-error" $ N.withSocketsDo $ do
Expand Down

0 comments on commit 1451ac7

Please sign in to comment.