Skip to content

Commit 0fd4f11

Browse files
committed
supporting non-threaded RTS on Unix in gracefulClose.
1 parent be9cd0e commit 0fd4f11

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

Network/Socket/Shutdown.hs

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

15-
#if defined(mingw32_HOST_OS)
1615
import Control.Concurrent (threadDelay)
17-
#else
16+
#if !defined(mingw32_HOST_OS)
1817
import Control.Concurrent (putMVar, takeMVar, newEmptyMVar)
1918
import qualified GHC.Event as Ev
2019
import System.Posix.Types (Fd(..))
@@ -65,11 +64,17 @@ gracefulClose s tmout = sendRecvFIN `E.finally` close s
6564
-- Sending TCP FIN.
6665
shutdown s ShutdownSend
6766
-- Waiting TCP FIN.
68-
recvEOF
6967
#if defined(mingw32_HOST_OS)
68+
recvEOFloop
69+
#else
70+
mevmgr <- Ev.getSystemEventManager
71+
case mevmgr of
72+
Nothing -> recvEOFloop -- non-threaded RTS
73+
Just evmgr -> recvEOFev evmgr
74+
#endif
7075
-- milliseconds. Taken from BSD fast clock value.
7176
clock = 200
72-
recvEOF = E.bracket (mallocBytes bufSize) free $ loop 0
77+
recvEOFloop = E.bracket (mallocBytes bufSize) free $ loop 0
7378
where
7479
loop delay buf = do
7580
-- We don't check the (positive) length.
@@ -82,9 +87,8 @@ gracefulClose s tmout = sendRecvFIN `E.finally` close s
8287
when (r == -1 && delay' < tmout) $ do
8388
threadDelay (clock * 1000)
8489
loop delay' buf
85-
#else
86-
recvEOF = do
87-
Just evmgr <- Ev.getSystemEventManager
90+
#if !defined(mingw32_HOST_OS)
91+
recvEOFev evmgr = do
8892
tmmgr <- Ev.getSystemTimerManager
8993
mvar <- newEmptyMVar
9094
E.bracket (register evmgr tmmgr mvar) (unregister evmgr tmmgr) $ \_ -> do

0 commit comments

Comments
 (0)