{-# LINE 1 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
-- This is a non-portable linux only interface.

{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE GADTs               #-}
{-# LANGUAGE KindSignatures      #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE MonadComprehensions #-}
{-# LANGUAGE NamedFieldPuns      #-}
{-# LANGUAGE PatternSynonyms     #-}
{-# LANGUAGE Rank2Types          #-}
{-# LANGUAGE RecordWildCards     #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving  #-}
{-# LANGUAGE TypeApplications    #-}



module Network.Mux.TCPInfo.Linux
  ( StructTCPInfo (..)
  , SocketOption (TCPInfoSocketOption)
  ) where

import           Foreign.C
import           Foreign.Storable (Storable (..))
import           Network.Socket(SocketOption(..))


pattern TCPInfoSocketOption :: SocketOption
pattern $bTCPInfoSocketOption :: SocketOption
$mTCPInfoSocketOption :: forall {r}. SocketOption -> ((# #) -> r) -> ((# #) -> r) -> r
TCPInfoSocketOption = SockOpt 6 11

data StructTCPInfo = StructTCPInfo {
    StructTCPInfo -> CUChar
tcpi_state  :: CUChar,
    StructTCPInfo -> CUChar
tcpi_ca_state :: CUChar,
    StructTCPInfo -> CUChar
tcpi_retransmits :: CUChar,
    StructTCPInfo -> CUChar
tcpi_probes :: CUChar,
    StructTCPInfo -> CUChar
tcpi_backoff :: CUChar,
    StructTCPInfo -> CUChar
tcpi_options :: CUChar,
    StructTCPInfo -> CUChar
tcpi_sndrcv_wscale :: CUChar,
    StructTCPInfo -> CUChar
tcpi_delivery_rate_app_limited_fastopen_client_fail :: CUChar,

    StructTCPInfo -> CUInt
tcpi_rto :: CUInt,
    StructTCPInfo -> CUInt
tcpi_ato :: CUInt,
    StructTCPInfo -> CUInt
tcpi_snd_mss :: CUInt,
    StructTCPInfo -> CUInt
tcpi_rcv_mss :: CUInt,

    StructTCPInfo -> CUInt
tcpi_unacked :: CUInt,
    StructTCPInfo -> CUInt
tcpi_sacked :: CUInt,
    StructTCPInfo -> CUInt
tcpi_lost :: CUInt,
    StructTCPInfo -> CUInt
tcpi_retrans :: CUInt,
    StructTCPInfo -> CUInt
tcpi_fackets :: CUInt,

    StructTCPInfo -> CUInt
tcpi_last_data_sent :: CUInt,
    StructTCPInfo -> CUInt
tcpi_last_ack_sent :: CUInt,
    StructTCPInfo -> CUInt
tcpi_last_data_recv :: CUInt,
    StructTCPInfo -> CUInt
tcpi_last_ack_recv :: CUInt,

    StructTCPInfo -> CUInt
tcpi_pmtu :: CUInt,
    StructTCPInfo -> CUInt
tcpi_rcv_ssthresh :: CUInt,
    StructTCPInfo -> CUInt
tcpi_rtt :: CUInt,
    StructTCPInfo -> CUInt
tcpi_rttvar :: CUInt,
    StructTCPInfo -> CUInt
tcpi_snd_ssthresh :: CUInt,
    StructTCPInfo -> CUInt
tcpi_snd_cwnd :: CUInt,
    StructTCPInfo -> CUInt
tcpi_advmss :: CUInt,
    StructTCPInfo -> CUInt
tcpi_reordering :: CUInt,

    StructTCPInfo -> CUInt
tcpi_rcv_rtt :: CUInt,
    StructTCPInfo -> CUInt
tcpi_rcv_space :: CUInt,

    StructTCPInfo -> CUInt
tcpi_total_retrans :: CUInt
  }
  deriving (StructTCPInfo -> StructTCPInfo -> Bool
(StructTCPInfo -> StructTCPInfo -> Bool)
-> (StructTCPInfo -> StructTCPInfo -> Bool) -> Eq StructTCPInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: StructTCPInfo -> StructTCPInfo -> Bool
== :: StructTCPInfo -> StructTCPInfo -> Bool
$c/= :: StructTCPInfo -> StructTCPInfo -> Bool
/= :: StructTCPInfo -> StructTCPInfo -> Bool
Eq, Eq StructTCPInfo
Eq StructTCPInfo =>
(StructTCPInfo -> StructTCPInfo -> Ordering)
-> (StructTCPInfo -> StructTCPInfo -> Bool)
-> (StructTCPInfo -> StructTCPInfo -> Bool)
-> (StructTCPInfo -> StructTCPInfo -> Bool)
-> (StructTCPInfo -> StructTCPInfo -> Bool)
-> (StructTCPInfo -> StructTCPInfo -> StructTCPInfo)
-> (StructTCPInfo -> StructTCPInfo -> StructTCPInfo)
-> Ord StructTCPInfo
StructTCPInfo -> StructTCPInfo -> Bool
StructTCPInfo -> StructTCPInfo -> Ordering
StructTCPInfo -> StructTCPInfo -> StructTCPInfo
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
$ccompare :: StructTCPInfo -> StructTCPInfo -> Ordering
compare :: StructTCPInfo -> StructTCPInfo -> Ordering
$c< :: StructTCPInfo -> StructTCPInfo -> Bool
< :: StructTCPInfo -> StructTCPInfo -> Bool
$c<= :: StructTCPInfo -> StructTCPInfo -> Bool
<= :: StructTCPInfo -> StructTCPInfo -> Bool
$c> :: StructTCPInfo -> StructTCPInfo -> Bool
> :: StructTCPInfo -> StructTCPInfo -> Bool
$c>= :: StructTCPInfo -> StructTCPInfo -> Bool
>= :: StructTCPInfo -> StructTCPInfo -> Bool
$cmax :: StructTCPInfo -> StructTCPInfo -> StructTCPInfo
max :: StructTCPInfo -> StructTCPInfo -> StructTCPInfo
$cmin :: StructTCPInfo -> StructTCPInfo -> StructTCPInfo
min :: StructTCPInfo -> StructTCPInfo -> StructTCPInfo
Ord, Int -> StructTCPInfo -> ShowS
[StructTCPInfo] -> ShowS
StructTCPInfo -> String
(Int -> StructTCPInfo -> ShowS)
-> (StructTCPInfo -> String)
-> ([StructTCPInfo] -> ShowS)
-> Show StructTCPInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> StructTCPInfo -> ShowS
showsPrec :: Int -> StructTCPInfo -> ShowS
$cshow :: StructTCPInfo -> String
show :: StructTCPInfo -> String
$cshowList :: [StructTCPInfo] -> ShowS
showList :: [StructTCPInfo] -> ShowS
Show)

instance Storable StructTCPInfo where
    sizeOf :: StructTCPInfo -> Int
sizeOf    StructTCPInfo
_ = (Int
104)
{-# LINE 75 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
    alignment _ = alignment (0 :: CInt)

    peek :: Ptr StructTCPInfo -> IO StructTCPInfo
peek Ptr StructTCPInfo
p = do
      tcpi_state <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUChar
forall b. Ptr b -> Int -> IO CUChar
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
0)) Ptr StructTCPInfo
p
{-# LINE 79 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_ca_state <- ((\hsc_ptr -> peekByteOff hsc_ptr 1)) p
{-# LINE 80 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_retransmits <- ((\hsc_ptr -> peekByteOff hsc_ptr 2)) p
{-# LINE 81 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_probes <- ((\hsc_ptr -> peekByteOff hsc_ptr 3)) p
{-# LINE 82 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_backoff <- ((\hsc_ptr -> peekByteOff hsc_ptr 4)) p
{-# LINE 83 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_options <- ((\hsc_ptr -> peekByteOff hsc_ptr 5)) p
{-# LINE 84 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      let tcpi_sndrcv_wscale = 0
          -- XXX can't cope with bitfields
          tcpi_delivery_rate_app_limited_fastopen_client_fail = 0

      tcpi_rto <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
8)) p
{-# LINE 89 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_ato <- ((\hsc_ptr -> peekByteOff hsc_ptr 12)) p
{-# LINE 90 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_snd_mss <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) p
{-# LINE 91 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_rcv_mss <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) p
{-# LINE 92 "src/Network/Mux/TCPInfo/Linux.hsc" #-}

      tcpi_unacked <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
24)) p
{-# LINE 94 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_sacked <- ((\hsc_ptr -> peekByteOff hsc_ptr 28)) p
{-# LINE 95 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_lost <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) p
{-# LINE 96 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_retrans <- ((\hsc_ptr -> peekByteOff hsc_ptr 36)) p
{-# LINE 97 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_fackets <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) p
{-# LINE 98 "src/Network/Mux/TCPInfo/Linux.hsc" #-}

      tcpi_last_data_sent <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
44)) p
{-# LINE 100 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_last_ack_sent <- ((\hsc_ptr -> peekByteOff hsc_ptr 48)) p
{-# LINE 101 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_last_data_recv <- ((\hsc_ptr -> peekByteOff hsc_ptr 52)) p
{-# LINE 102 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_last_ack_recv <- ((\hsc_ptr -> peekByteOff hsc_ptr 56)) p
{-# LINE 103 "src/Network/Mux/TCPInfo/Linux.hsc" #-}

      tcpi_pmtu <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
60)) p
{-# LINE 105 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_rcv_ssthresh <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) p
{-# LINE 106 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_rtt <- ((\hsc_ptr -> peekByteOff hsc_ptr 68)) p
{-# LINE 107 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_rttvar <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) p
{-# LINE 108 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_snd_ssthresh <- ((\hsc_ptr -> peekByteOff hsc_ptr 76)) p
{-# LINE 109 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_snd_cwnd <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) p
{-# LINE 110 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_advmss <- ((\hsc_ptr -> peekByteOff hsc_ptr 84)) p
{-# LINE 111 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_reordering <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) p
{-# LINE 112 "src/Network/Mux/TCPInfo/Linux.hsc" #-}

      tcpi_rcv_rtt <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
92)) p
{-# LINE 114 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      tcpi_rcv_space <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) p
{-# LINE 115 "src/Network/Mux/TCPInfo/Linux.hsc" #-}

      tcpi_total_retrans <- ((\Ptr StructTCPInfo
hsc_ptr -> Ptr StructTCPInfo -> Int -> IO CUInt
forall b. Ptr b -> Int -> IO CUInt
forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr StructTCPInfo
hsc_ptr Int
100)) p
{-# LINE 117 "src/Network/Mux/TCPInfo/Linux.hsc" #-}
      return $ StructTCPInfo {..}


    -- This is a readonly kernel interface. We shouldn't be writing to
    -- this structure.
    poke :: Ptr StructTCPInfo -> StructTCPInfo -> IO ()
poke Ptr StructTCPInfo
_ StructTCPInfo
_ = String -> IO ()
forall a. HasCallStack => String -> a
error String
"Writing to StructTCPInfo"