Skip to content

Commit 107486a

Browse files
committed
using yield
1 parent 29f4e61 commit 107486a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Network/Socket/Shutdown.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Network.Socket.Shutdown (
1111
import qualified Control.Exception as E
1212
import Foreign.Marshal.Alloc (mallocBytes, free)
1313

14-
import Control.Concurrent (threadDelay)
14+
import Control.Concurrent (threadDelay, yield)
1515

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

0 commit comments

Comments
 (0)