Skip to content

Commit

Permalink
Merge PR haskell#340.
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jul 5, 2018
2 parents 7eb8af5 + 2a70aa1 commit ffc1dd3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Network/Socket/ByteString/Lazy/Posix.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}

module Network.Socket.ByteString.Lazy.Posix (
-- * Send data to a socket
Expand Down Expand Up @@ -50,6 +51,7 @@ sendAll
:: Socket -- ^ Connected socket
-> L.ByteString -- ^ Data to send
-> IO ()
sendAll _ "" = return ()
sendAll s bs = do
sent <- send s bs
waitWhen0 (fromIntegral sent) s
Expand Down
3 changes: 3 additions & 0 deletions Network/Socket/ByteString/Lazy/Windows.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}

module Network.Socket.ByteString.Lazy.Windows (
-- * Send data to a socket
send
Expand Down Expand Up @@ -26,6 +28,7 @@ sendAll
:: Socket -- ^ Connected socket
-> L.ByteString -- ^ Data to send
-> IO ()
sendAll _ "" = return ()
sendAll s bs = do
sent <- send s bs
waitWhen0 (fromIntegral sent) s
Expand Down
8 changes: 8 additions & 0 deletions tests/SimpleSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as C
import qualified Data.ByteString.Lazy as L
import Network.Socket
import Network.Socket.ByteString
import qualified Network.Socket.ByteString.Lazy as Lazy
import System.Directory
import System.Timeout (timeout)

Expand Down Expand Up @@ -183,6 +185,12 @@ spec = do
addr `shouldBe` (SockAddrUnix "")
unixTest client server

describe "Lazy.sendAll" $ do
it "works well" $ do
let server sock = recv sock 1024 `shouldReturn` testMsg
client sock = Lazy.sendAll sock $ L.fromChunks [testMsg]
tcpTest client server

------------------------------------------------------------------------

serverAddr :: String
Expand Down

0 comments on commit ffc1dd3

Please sign in to comment.