@@ -12,9 +12,8 @@ module Network.Socket.Shutdown (
12
12
import qualified Control.Exception as E
13
13
import Foreign.Marshal.Alloc (mallocBytes , free )
14
14
15
- #if defined(mingw32_HOST_OS)
16
15
import Control.Concurrent (threadDelay )
17
- #else
16
+ #if !defined(mingw32_HOST_OS)
18
17
import Control.Concurrent (putMVar , takeMVar , newEmptyMVar )
19
18
import qualified GHC.Event as Ev
20
19
import System.Posix.Types (Fd (.. ))
@@ -65,11 +64,17 @@ gracefulClose s tmout = sendRecvFIN `E.finally` close s
65
64
-- Sending TCP FIN.
66
65
shutdown s ShutdownSend
67
66
-- Waiting TCP FIN.
68
- recvEOF
69
67
#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
70
75
-- milliseconds. Taken from BSD fast clock value.
71
76
clock = 200
72
- recvEOF = E. bracket (mallocBytes bufSize) free $ loop 0
77
+ recvEOFloop = E. bracket (mallocBytes bufSize) free $ loop 0
73
78
where
74
79
loop delay buf = do
75
80
-- We don't check the (positive) length.
@@ -82,9 +87,8 @@ gracefulClose s tmout = sendRecvFIN `E.finally` close s
82
87
when (r == - 1 && delay' < tmout) $ do
83
88
threadDelay (clock * 1000 )
84
89
loop delay' buf
85
- #else
86
- recvEOF = do
87
- Just evmgr <- Ev. getSystemEventManager
90
+ #if !defined(mingw32_HOST_OS)
91
+ recvEOFev evmgr = do
88
92
tmmgr <- Ev. getSystemTimerManager
89
93
mvar <- newEmptyMVar
90
94
E. bracket (register evmgr tmmgr mvar) (unregister evmgr tmmgr) $ \ _ -> do
0 commit comments