Skip to content

Commit

Permalink
using yield
Browse files Browse the repository at this point in the history
  • Loading branch information
kazu-yamamoto committed Jun 10, 2024
1 parent 507ab0e commit b3c898e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Network/Socket/Shutdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Network.Socket.Shutdown (
import qualified Control.Exception as E
import Foreign.Marshal.Alloc (mallocBytes, free)

import Control.Concurrent (threadDelay)
import Control.Concurrent (threadDelay, yield)

import Network.Socket.Buffer
import Network.Socket.Imports
Expand Down Expand Up @@ -55,6 +55,9 @@ gracefulClose s tmout0 = sendRecvFIN `E.finally` close s
case ex of
Left (E.SomeException _) -> return ()
Right () -> do
-- Giving CPU time to other threads hoping that
-- FIN arrives meanwhile.
yield
-- Waiting TCP FIN.
E.bracket (mallocBytes bufSize) free recvEOFloop
recvEOFloop buf = loop 1 0
Expand Down

0 comments on commit b3c898e

Please sign in to comment.