Skip to content

Commit

Permalink
using the same logic for sendAll and sendAllTo
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jan 20, 2022
1 parent 9b2d9b7 commit afce6a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
11 changes: 7 additions & 4 deletions Network/Socket/ByteString/IO.hsc
Expand Up @@ -126,10 +126,13 @@ sendAllTo :: SocketAddress sa =>
-> sa -- ^ Recipient address
-> IO ()
sendAllTo _ "" _ = return ()
sendAllTo s xs sa = do
sent <- sendTo s xs sa
waitWhen0 sent s
when (sent >= 0) $ sendAllTo s (B.drop sent xs) sa
sendAllTo s bs0 sa = loop bs0
where
loop bs = do
-- "send" throws an exception.
sent <- sendTo s bs sa
waitWhen0 sent s
when (sent /= B.length bs) $ loop $ B.drop sent bs

-- | Send data to the socket. The socket must be in a connected
-- state. The data is sent as if the parts have been concatenated.
Expand Down
12 changes: 7 additions & 5 deletions Network/Socket/ByteString/Lazy/Posix.hs
Expand Up @@ -51,8 +51,10 @@ sendAll
-> L.ByteString -- ^ Data to send
-> IO ()
sendAll _ "" = return ()
sendAll s bs = do
-- "send" throws an exception.
sent <- send s bs
waitWhen0 (fromIntegral sent) s
when (sent /= L.length bs) $ sendAll s $ L.drop sent bs
sendAll s bs0 = loop bs0
where
loop bs = do
-- "send" throws an exception.
sent <- send s bs
waitWhen0 (fromIntegral sent) s
when (sent /= L.length bs) $ loop $ L.drop sent bs
12 changes: 7 additions & 5 deletions Network/Socket/ByteString/Lazy/Windows.hs
Expand Up @@ -29,8 +29,10 @@ sendAll
-> L.ByteString -- ^ Data to send
-> IO ()
sendAll _ "" = return ()
sendAll s bs = do
-- "send" throws an exception.
sent <- send s bs
waitWhen0 (fromIntegral sent) s
when (sent /= L.length bs) $ sendAll s $ L.drop sent bs
sendAll s bs0 = loop bs0
where
loop bs = do
-- "send" throws an exception.
sent <- send s bs
waitWhen0 (fromIntegral sent) s
when (sent /= L.length bs) $ loop $ L.drop sent bs

0 comments on commit afce6a8

Please sign in to comment.