From 107486a23bf8574615eeacbccc1c3ada9042417f Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 11 Jun 2024 08:20:57 +0900 Subject: [PATCH] using yield --- Network/Socket/Shutdown.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Network/Socket/Shutdown.hs b/Network/Socket/Shutdown.hs index 85ab732f..e6f9048a 100644 --- a/Network/Socket/Shutdown.hs +++ b/Network/Socket/Shutdown.hs @@ -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 @@ -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