{-# LANGUAGE RecordWildCards #-}
module Network.HTTP2.H2.Config where
import Data.IORef
import Foreign.Marshal.Alloc (free, mallocBytes)
import Network.HTTP.Semantics.Client
import Network.Socket
import Network.Socket.ByteString (sendAll)
import qualified System.TimeManager as T
import Network.HPACK
import Network.HTTP2.H2.Types
allocSimpleConfig :: Socket -> BufferSize -> IO Config
allocSimpleConfig :: Socket -> Int -> IO Config
allocSimpleConfig Socket
s Int
bufsiz = Socket -> Int -> Int -> IO Config
allocSimpleConfig' Socket
s Int
bufsiz (Int
30 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
1000000)
allocSimpleConfig' :: Socket -> BufferSize -> Int -> IO Config
allocSimpleConfig' :: Socket -> Int -> Int -> IO Config
allocSimpleConfig' Socket
s Int
bufsiz Int
usec = do
Ptr Word8
confWriteBuffer <- Int -> IO (Ptr Word8)
forall a. Int -> IO (Ptr a)
mallocBytes Int
bufsiz
let confBufferSize :: Int
confBufferSize = Int
bufsiz
let confSendAll :: ByteString -> IO ()
confSendAll = Socket -> ByteString -> IO ()
sendAll Socket
s
ReadN
confReadN <- Socket -> IORef (Maybe ByteString) -> ReadN
defaultReadN Socket
s (IORef (Maybe ByteString) -> ReadN)
-> IO (IORef (Maybe ByteString)) -> IO ReadN
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ByteString -> IO (IORef (Maybe ByteString))
forall a. a -> IO (IORef a)
newIORef Maybe ByteString
forall a. Maybe a
Nothing
let confPositionReadMaker :: PositionReadMaker
confPositionReadMaker = PositionReadMaker
defaultPositionReadMaker
Manager
confTimeoutManager <- Int -> IO Manager
T.initialize Int
usec
SockAddr
confMySockAddr <- Socket -> IO SockAddr
getSocketName Socket
s
SockAddr
confPeerSockAddr <- Socket -> IO SockAddr
getPeerName Socket
s
let confReadNTimeout :: Bool
confReadNTimeout = Bool
False
Config -> IO Config
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Config{Bool
Int
Ptr Word8
SockAddr
Manager
ReadN
PositionReadMaker
ByteString -> IO ()
confWriteBuffer :: Ptr Word8
confBufferSize :: Int
confSendAll :: ByteString -> IO ()
confReadN :: ReadN
confPositionReadMaker :: PositionReadMaker
confTimeoutManager :: Manager
confMySockAddr :: SockAddr
confPeerSockAddr :: SockAddr
confReadNTimeout :: Bool
confReadNTimeout :: Bool
confPeerSockAddr :: SockAddr
confMySockAddr :: SockAddr
confTimeoutManager :: Manager
confPositionReadMaker :: PositionReadMaker
confReadN :: ReadN
confSendAll :: ByteString -> IO ()
confBufferSize :: Int
confWriteBuffer :: Ptr Word8
..}
freeSimpleConfig :: Config -> IO ()
freeSimpleConfig :: Config -> IO ()
freeSimpleConfig Config
conf = do
Ptr Word8 -> IO ()
forall a. Ptr a -> IO ()
free (Ptr Word8 -> IO ()) -> Ptr Word8 -> IO ()
forall a b. (a -> b) -> a -> b
$ Config -> Ptr Word8
confWriteBuffer Config
conf
Manager -> IO ()
T.killManager (Manager -> IO ()) -> Manager -> IO ()
forall a b. (a -> b) -> a -> b
$ Config -> Manager
confTimeoutManager Config
conf