{-# LINE 1 "src/Network/Riak/Connection/NoPush.hsc" #-}
{-# LANGUAGE ForeignFunctionInterface #-}

-- |
-- Module:      Network.Riak.Connection.NoPush
-- Copyright:   (c) 2011 MailRank, Inc.
-- License:     Apache
-- Maintainer:  Mark Hibberd <mark@hibberd.id.au>, Nathan Hunter <nhunter@janrain.com>
-- Stability:   experimental
-- Portability: portable
--
-- TCP madness.

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, fdSocket)

noPush :: CInt

{-# LINE 33 "src/Network/Riak/Connection/NoPush.hsc" #-}
noPush :: CInt
noPush = CInt
3
{-# LINE 34 "src/Network/Riak/Connection/NoPush.hsc" #-}

{-# LINE 37 "src/Network/Riak/Connection/NoPush.hsc" #-}

setNoPush :: Socket -> Bool -> IO ()
setNoPush :: Socket -> Bool -> IO ()
setNoPush Socket
_ Bool
_ | CInt
noPush CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
0 = () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
-- setNoPush (MkSocket fd _ _ _ _) onOff = do
setNoPush Socket
s Bool
onOff = do
  let v :: CInt
v = if Bool
onOff then CInt
1 else CInt
0
  CInt -> (Ptr CInt -> IO ()) -> IO ()
forall a b. Storable a => a -> (Ptr a -> IO b) -> IO b
with CInt
v ((Ptr CInt -> IO ()) -> IO ()) -> (Ptr CInt -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CInt
ptr ->
    String -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> IO a -> IO ()
throwErrnoIfMinus1_ String
"setNoPush" (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$ do
      CInt
a <- (Socket -> IO CInt
fdSocket Socket
s)
      CInt -> CInt -> CInt -> Ptr CInt -> CInt -> IO CInt
c_setsockopt CInt
a (CInt
6) CInt
noPush Ptr CInt
ptr (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Int
forall a. Storable a => a -> Int
sizeOf CInt
v))
{-# LINE 47 "src/Network/Riak/Connection/NoPush.hsc" #-}

foreign import ccall unsafe "setsockopt"
  c_setsockopt :: CInt -> CInt -> CInt -> Ptr CInt -> CInt -> IO CInt