module Network.Riak.Connection.NoPush (setNoPush) where
import Foreign.C.Error (throwErrnoIfMinus1_)
import Foreign.C.Types (CInt(..))
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr)
import Foreign.Storable (sizeOf)
import Network.Socket (Socket(..))
noPush :: CInt
noPush = 3
setNoPush :: Socket -> Bool -> IO ()
setNoPush _ _ | noPush == 0 = return ()
setNoPush (MkSocket fd _ _ _ _) onOff = do
let v = if onOff then 1 else 0
with v $ \ptr ->
throwErrnoIfMinus1_ "setNoPush" $
c_setsockopt fd (6) noPush ptr (fromIntegral (sizeOf v))
foreign import ccall unsafe "setsockopt"
c_setsockopt :: CInt -> CInt -> CInt -> Ptr CInt -> CInt -> IO CInt