{-# LANGUAGE CPP #-}
module Network.Socket.STM (
waitReadSocketSTM,
waitAndCancelReadSocketSTM,
waitWriteSocketSTM,
waitAndCancelWriteSocketSTM,
) where
import Control.Concurrent.STM (STM)
import Network.Socket.Types
#if !defined(mingw32_HOST_OS)
import Control.Concurrent (threadWaitReadSTM, threadWaitWriteSTM)
import System.Posix.Types (Fd (..))
#endif
waitReadSocketSTM :: Socket -> IO (STM ())
waitReadSocketSTM :: Socket -> IO (STM ())
waitReadSocketSTM Socket
s = (STM (), IO ()) -> STM ()
forall a b. (a, b) -> a
fst ((STM (), IO ()) -> STM ()) -> IO (STM (), IO ()) -> IO (STM ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Socket -> IO (STM (), IO ())
waitAndCancelReadSocketSTM Socket
s
waitAndCancelReadSocketSTM :: Socket -> IO (STM (), IO ())
#if defined(mingw32_HOST_OS)
waitAndCancelReadSocketSTM _ =
ioError $
userError $
"waitAndCancelReadSocketSTM: Windows completion ports do not "
++ "provide readiness notification; use recvBufWith or "
++ "Network.Socket.ByteString.recvWith instead"
#else
waitAndCancelReadSocketSTM :: Socket -> IO (STM (), IO ())
waitAndCancelReadSocketSTM Socket
s = Socket -> (CInt -> IO (STM (), IO ())) -> IO (STM (), IO ())
forall r. Socket -> (CInt -> IO r) -> IO r
withFdSocket Socket
s ((CInt -> IO (STM (), IO ())) -> IO (STM (), IO ()))
-> (CInt -> IO (STM (), IO ())) -> IO (STM (), IO ())
forall a b. (a -> b) -> a -> b
$ Fd -> IO (STM (), IO ())
threadWaitReadSTM (Fd -> IO (STM (), IO ()))
-> (CInt -> Fd) -> CInt -> IO (STM (), IO ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> Fd
Fd
#endif
waitWriteSocketSTM :: Socket -> IO (STM ())
waitWriteSocketSTM :: Socket -> IO (STM ())
waitWriteSocketSTM Socket
s = (STM (), IO ()) -> STM ()
forall a b. (a, b) -> a
fst ((STM (), IO ()) -> STM ()) -> IO (STM (), IO ()) -> IO (STM ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Socket -> IO (STM (), IO ())
waitAndCancelWriteSocketSTM Socket
s
waitAndCancelWriteSocketSTM :: Socket -> IO (STM (), IO ())
#if defined(mingw32_HOST_OS)
waitAndCancelWriteSocketSTM _ =
ioError $
userError $
"waitAndCancelWriteSocketSTM: Windows completion ports do not "
++ "provide readiness notification, and none is needed for "
++ "sending: issue the send instead"
#else
waitAndCancelWriteSocketSTM :: Socket -> IO (STM (), IO ())
waitAndCancelWriteSocketSTM Socket
s = Socket -> (CInt -> IO (STM (), IO ())) -> IO (STM (), IO ())
forall r. Socket -> (CInt -> IO r) -> IO r
withFdSocket Socket
s ((CInt -> IO (STM (), IO ())) -> IO (STM (), IO ()))
-> (CInt -> IO (STM (), IO ())) -> IO (STM (), IO ())
forall a b. (a -> b) -> a -> b
$ Fd -> IO (STM (), IO ())
threadWaitWriteSTM (Fd -> IO (STM (), IO ()))
-> (CInt -> Fd) -> CInt -> IO (STM (), IO ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CInt -> Fd
Fd
#endif