Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for network-3.0.0.0 #65

Merged
merged 3 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By PVP this has to be a minor version bump, but I'll fix it post-facto

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
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -124,7 +124,7 @@ Library
attoparsec >= 0.10 && <0.14,
bytestring >= 0.9 && <0.11,
bytestring-builder >= 0.10 && <0.11,
network >= 2.3 && <2.9,
network >= 2.3 && <3.1,
primitive >= 0.2 && <0.7,
process >= 1.1 && <1.7,
text >= 0.10 && <1.3,
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