{-# LINE 1 "src/Ouroboros/Network/Linger.hsc" #-}


module Ouroboros.Network.Linger
  ( StructLinger (..)
  ) where

import           Foreign.C (CInt)
import           Foreign.Storable (Storable (..))


-- TODO: to be removed once a new version of `network` library is released.
data StructLinger = StructLinger {
    -- | Set the linger option on.
    StructLinger -> CInt
sl_onoff  :: CInt,

    -- | Linger timeout.
    StructLinger -> CInt
sl_linger :: CInt
  }
  deriving (StructLinger -> StructLinger -> Bool
(StructLinger -> StructLinger -> Bool)
-> (StructLinger -> StructLinger -> Bool) -> Eq StructLinger
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StructLinger -> StructLinger -> Bool
$c/= :: StructLinger -> StructLinger -> Bool
== :: StructLinger -> StructLinger -> Bool
$c== :: StructLinger -> StructLinger -> Bool
Eq, Eq StructLinger
Eq StructLinger
-> (StructLinger -> StructLinger -> Ordering)
-> (StructLinger -> StructLinger -> Bool)
-> (StructLinger -> StructLinger -> Bool)
-> (StructLinger -> StructLinger -> Bool)
-> (StructLinger -> StructLinger -> Bool)
-> (StructLinger -> StructLinger -> StructLinger)
-> (StructLinger -> StructLinger -> StructLinger)
-> Ord StructLinger
StructLinger -> StructLinger -> Bool
StructLinger -> StructLinger -> Ordering
StructLinger -> StructLinger -> StructLinger
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: StructLinger -> StructLinger -> StructLinger
$cmin :: StructLinger -> StructLinger -> StructLinger
max :: StructLinger -> StructLinger -> StructLinger
$cmax :: StructLinger -> StructLinger -> StructLinger
>= :: StructLinger -> StructLinger -> Bool
$c>= :: StructLinger -> StructLinger -> Bool
> :: StructLinger -> StructLinger -> Bool
$c> :: StructLinger -> StructLinger -> Bool
<= :: StructLinger -> StructLinger -> Bool
$c<= :: StructLinger -> StructLinger -> Bool
< :: StructLinger -> StructLinger -> Bool
$c< :: StructLinger -> StructLinger -> Bool
compare :: StructLinger -> StructLinger -> Ordering
$ccompare :: StructLinger -> StructLinger -> Ordering
$cp1Ord :: Eq StructLinger
Ord, Int -> StructLinger -> ShowS
[StructLinger] -> ShowS
StructLinger -> String
(Int -> StructLinger -> ShowS)
-> (StructLinger -> String)
-> ([StructLinger] -> ShowS)
-> Show StructLinger
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StructLinger] -> ShowS
$cshowList :: [StructLinger] -> ShowS
show :: StructLinger -> String
$cshow :: StructLinger -> String
showsPrec :: Int -> StructLinger -> ShowS
$cshowsPrec :: Int -> StructLinger -> ShowS
Show)

instance Storable StructLinger where
    sizeOf :: StructLinger -> Int
sizeOf    StructLinger
_ = (Int
8)
{-# LINE 23 "src/Ouroboros/Network/Linger.hsc" #-}
    alignment _ = alignment (0 :: CInt)

    peek :: Ptr StructLinger -> IO StructLinger
peek Ptr StructLinger
p = do
        CInt
onoff  <- ((\Ptr StructLinger
hsc_ptr -> Ptr StructLinger -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructLinger
hsc_ptr Int
0)) Ptr StructLinger
p
{-# LINE 27 "src/Ouroboros/Network/Linger.hsc" #-}
        CInt
linger <- ((\Ptr StructLinger
hsc_ptr -> Ptr StructLinger -> Int -> IO CInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructLinger
hsc_ptr Int
4)) Ptr StructLinger
p
{-# LINE 28 "src/Ouroboros/Network/Linger.hsc" #-}
        StructLinger -> IO StructLinger
forall (m :: * -> *) a. Monad m => a -> m a
return (StructLinger -> IO StructLinger)
-> StructLinger -> IO StructLinger
forall a b. (a -> b) -> a -> b
$ CInt -> CInt -> StructLinger
StructLinger CInt
onoff CInt
linger

    poke :: Ptr StructLinger -> StructLinger -> IO ()
poke Ptr StructLinger
p (StructLinger CInt
onoff CInt
linger) = do
        ((\Ptr StructLinger
hsc_ptr -> Ptr StructLinger -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr StructLinger
hsc_ptr Int
0))  Ptr StructLinger
p CInt
onoff
{-# LINE 32 "src/Ouroboros/Network/Linger.hsc" #-}
        ((\Ptr StructLinger
hsc_ptr -> Ptr StructLinger -> Int -> CInt -> IO ()
forall a b. Storable a => Ptr b -> Int -> a -> IO ()
pokeByteOff Ptr StructLinger
hsc_ptr Int
4)) Ptr StructLinger
p CInt
linger
{-# LINE 33 "src/Ouroboros/Network/Linger.hsc" #-}