File: Windows.hs

package info (click to toggle)
haskell-recv 0.1.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 76 kB
  • sloc: haskell: 208; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE CPP #-}
module Network.Socket.BufferPool.Windows
  ( windowsThreadBlockHack
  ) where

#ifdef mingw32_HOST_OS
import Control.Concurrent.MVar
import Control.Concurrent
import qualified Control.Exception
import Control.Monad

-- | Allow main socket listening thread to be interrupted on Windows platform
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack act = do
    var <- newEmptyMVar :: IO (MVar (Either Control.Exception.SomeException a))
    -- Catch and rethrow even async exceptions, so don't bother with UnliftIO
    void . forkIO $ Control.Exception.try act >>= putMVar var
    res <- takeMVar var
    case res of
      Left  e -> Control.Exception.throwIO e
      Right r -> return r
#else
windowsThreadBlockHack :: IO a -> IO a
windowsThreadBlockHack = id
#endif