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

#54 Use system value for defaultReadBufferSize #55

Merged
merged 1 commit into from
Jan 5, 2020
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
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