{-# LANGUAGE CPP #-}

module Network.QUIC.Imports (
    Bytes
  , ByteString(..)
  , ShortByteString(..)
  , Builder
  , module Control.Applicative
  , module Control.Monad
  , module Data.Bits
  , module Data.Foldable
  , module Data.IORef
  , module Data.Int
  , module Data.Monoid
  , module Data.Ord
  , module Data.Word
  , module Data.Array
  , module Data.Array.IO
  , module Data.Maybe
  , module Numeric
  , module Network.ByteOrder
  , module Network.QUIC.Utils
#if !MIN_VERSION_base(4,17,0)
  , (!<<.), (!>>.)
#endif
  , atomicModifyIORef''
  , copyBS
  ) where

import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.IO
import Data.Bits
import Data.ByteString.Builder (Builder)
import Data.ByteString.Internal (ByteString(..), memcpy)
import Data.ByteString.Short.Internal (ShortByteString(..))
import Data.Foldable
import Data.IORef
import Data.Int
import Data.Maybe
import Data.Monoid
import Data.Ord
import Data.Word
import Foreign.ForeignPtr
import Foreign.Ptr
import Network.ByteOrder
import Network.QUIC.Utils
import Numeric

-- | All internal byte sequences.
--   `ByteString` should be used for FFI related stuff.
type Bytes = ShortByteString

#if !MIN_VERSION_base(4,17,0)
infixl 8 !<<.
(!<<.) :: Bits a => a -> Int -> a
!<<. :: forall a. Bits a => a -> Int -> a
(!<<.) = forall a. Bits a => a -> Int -> a
unsafeShiftL

infixl 8 !>>.
(!>>.) :: Bits a => a -> Int -> a
!>>. :: forall a. Bits a => a -> Int -> a
(!>>.) = forall a. Bits a => a -> Int -> a
unsafeShiftR
#endif

atomicModifyIORef'' :: IORef a -> (a -> a) -> IO ()
atomicModifyIORef'' :: forall a. IORef a -> (a -> a) -> IO ()
atomicModifyIORef'' IORef a
ref a -> a
f = forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef a
ref forall a b. (a -> b) -> a -> b
$ \a
x -> (a -> a
f a
x, ())

copyBS :: Buffer -> ByteString -> IO Int
copyBS :: Buffer -> ByteString -> IO Int
copyBS Buffer
dst (PS ForeignPtr Word8
fptr Int
off Int
len) = forall a b. ForeignPtr a -> (Ptr a -> IO b) -> IO b
withForeignPtr ForeignPtr Word8
fptr forall a b. (a -> b) -> a -> b
$ \Buffer
src0 -> do
    let src :: Ptr b
src = Buffer
src0 forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
off
    Buffer -> Buffer -> Int -> IO ()
memcpy Buffer
dst forall {b}. Ptr b
src Int
len
    forall (m :: * -> *) a. Monad m => a -> m a
return Int
len