Skip to content

Commit

Permalink
fpco#54 Use system value for defaultReadBufferSize
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain GERARD committed Jan 5, 2020
1 parent 64d1959 commit ce5cfe2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for streaming-commons

## 0.2.1.2

* Update `defaultReadBufferSize` to use system default instead of hardcoded value [#54](https://github.com/fpco/streaming-commons/issues/54)

## 0.2.1.1

* Fix a failing test case (invalid `ByteString` copying), does not affect library itself
Expand Down
8 changes: 5 additions & 3 deletions Data/Streaming/Network.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module Data.Streaming.Network
import qualified Network.Socket as NS
import Data.Streaming.Network.Internal
import Control.Concurrent (threadDelay)
import Control.Exception (IOException, try, SomeException, throwIO, bracketOnError)
import Control.Exception (IOException, try, SomeException, throwIO, bracketOnError, bracket)
import Network.Socket (Socket, AddrInfo, SocketType)
import Network.Socket.ByteString (recv, sendAll)
import System.IO.Error (isDoesNotExistError)
Expand All @@ -108,7 +108,7 @@ import Control.Concurrent (forkIO)
import Control.Monad (forever)
import Data.IORef (IORef, newIORef, atomicModifyIORef)
import Data.Array.Unboxed ((!), UArray, listArray)
import System.IO.Unsafe (unsafePerformIO)
import System.IO.Unsafe (unsafePerformIO, unsafeDupablePerformIO)
import System.Random (randomRIO)
import System.IO.Error (isFullErrorType, ioeGetErrorType)
#if WINDOWS
Expand Down Expand Up @@ -263,8 +263,10 @@ bindPortUDP = bindPortGen NS.Datagram
bindRandomPortUDP :: HostPreference -> IO (Int, Socket)
bindRandomPortUDP = bindRandomPortGen NS.Datagram

{-# NOINLINE defaultReadBufferSize #-}
defaultReadBufferSize :: Int
defaultReadBufferSize = 32768
defaultReadBufferSize = unsafeDupablePerformIO $
bracket (NS.socket NS.AF_INET NS.Stream 0) NS.close (\sock -> NS.getSocketOption sock NS.RecvBuffer)

#if !WINDOWS
-- | Attempt to connect to the given Unix domain socket path.
Expand Down
2 changes: 1 addition & 1 deletion streaming-commons.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: streaming-commons
version: 0.2.1.1
version: 0.2.1.2
synopsis: Common lower-level functions needed by various streaming data libraries
description: Provides low-dependency functionality commonly needed by various streaming data libraries, such as conduit and pipes.
homepage: https://github.com/fpco/streaming-commons
Expand Down
4 changes: 4 additions & 0 deletions test/Data/Streaming/NetworkSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import Test.Hspec.QuickCheck

spec :: Spec
spec = do
describe "getDefaultReadBufferSize" $ do
it "sanity" $ do
getReadBufferSize (clientSettingsTCP 8080 "localhost") >= 4096 `shouldBe` True

describe "getUnassignedPort" $ do
it "sanity" $ replicateM_ 100000 $ do
port <- getUnassignedPort
Expand Down

0 comments on commit ce5cfe2

Please sign in to comment.