{-# LANGUAGE CPP #-}
module Network.Socket.Fcntl where
import qualified System.Posix.Internals
#if !defined(mingw32_HOST_OS)
import Network.Socket.Cbits
#endif
import Network.Socket.Imports
setNonBlockIfNeeded :: CInt -> IO ()
setNonBlockIfNeeded :: CInt -> IO ()
setNonBlockIfNeeded CInt
fd =
CInt -> Bool -> IO ()
System.Posix.Internals.setNonBlockingFD CInt
fd Bool
True
setCloseOnExecIfNeeded :: CInt -> IO ()
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
setCloseOnExecIfNeeded _ = return ()
#else
setCloseOnExecIfNeeded :: CInt -> IO ()
setCloseOnExecIfNeeded CInt
fd = CInt -> IO ()
System.Posix.Internals.setCloseOnExec CInt
fd
#endif
#if !defined(mingw32_HOST_OS)
foreign import ccall unsafe "fcntl"
c_fcntl_read :: CInt -> CInt -> CInt -> IO CInt
#endif
getCloseOnExec :: CInt -> IO Bool
#if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS)
getCloseOnExec _ = return False
#else
getCloseOnExec :: CInt -> IO Bool
getCloseOnExec CInt
fd = do
CInt
flags <- CInt -> CInt -> CInt -> IO CInt
c_fcntl_read CInt
fd CInt
fGetFd CInt
0
let ret :: CInt
ret = CInt
flags CInt -> CInt -> CInt
forall a. Bits a => a -> a -> a
.&. CInt
fdCloexec
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
ret CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0)
#endif
getNonBlock :: CInt -> IO Bool
#if defined(mingw32_HOST_OS)
getNonBlock _ = return False
#else
getNonBlock :: CInt -> IO Bool
getNonBlock CInt
fd = do
CInt
flags <- CInt -> CInt -> CInt -> IO CInt
c_fcntl_read CInt
fd CInt
fGetFl CInt
0
let ret :: CInt
ret = CInt
flags CInt -> CInt -> CInt
forall a. Bits a => a -> a -> a
.&. CInt
oNonBlock
Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CInt
ret CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0)
#endif