{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Network.HTTP2.TLS.Config where
import Data.ByteString (ByteString)
import Foreign.Marshal.Alloc (free, mallocBytes)
import Network.HTTP2.Client (
Config (..),
defaultPositionReadMaker,
)
import Network.Socket (SockAddr)
import Network.Socket.BufferPool
import qualified System.TimeManager as T
import Network.HTTP2.TLS.Server.Settings
allocConfigForServer
:: Settings
-> T.Manager
-> (ByteString -> IO ())
-> IO ByteString
-> SockAddr
-> SockAddr
-> IO Config
allocConfigForServer :: Settings
-> Manager
-> (ByteString -> IO ())
-> IO ByteString
-> SockAddr
-> SockAddr
-> IO Config
allocConfigForServer Settings{Int
String -> IO ()
settingsConnectionWindowSize :: Settings -> Int
settingsStreamWindowSize :: Settings -> Int
settingsConcurrentStreams :: Settings -> Int
settingsNumberOfWorkers :: Settings -> Int
settingsKeyLogger :: Settings -> String -> IO ()
settingsReadBufferLowerLimit :: Settings -> Int
settingsReadBufferSize :: Settings -> Int
settingsSlowlorisSize :: Settings -> Int
settingsSendBufferSize :: Settings -> Int
settingsTimeout :: Settings -> Int
settingsConnectionWindowSize :: Int
settingsStreamWindowSize :: Int
settingsConcurrentStreams :: Int
settingsNumberOfWorkers :: Int
settingsKeyLogger :: String -> IO ()
settingsReadBufferLowerLimit :: Int
settingsReadBufferSize :: Int
settingsSlowlorisSize :: Int
settingsSendBufferSize :: Int
settingsTimeout :: Int
..} Manager
mgr ByteString -> IO ()
send IO ByteString
recv SockAddr
mysa SockAddr
peersa = do
Ptr Word8
buf <- forall a. Int -> IO (Ptr a)
mallocBytes Int
settingsSendBufferSize
RecvN
recvN <- ByteString -> IO ByteString -> IO RecvN
makeRecvN ByteString
"" IO ByteString
recv
let config :: Config
config =
Config
{ confWriteBuffer :: Ptr Word8
confWriteBuffer = Ptr Word8
buf
, confBufferSize :: Int
confBufferSize = Int
settingsSendBufferSize
, confSendAll :: ByteString -> IO ()
confSendAll = ByteString -> IO ()
send
, confReadN :: RecvN
confReadN = RecvN
recvN
, confPositionReadMaker :: PositionReadMaker
confPositionReadMaker = PositionReadMaker
defaultPositionReadMaker
, confTimeoutManager :: Manager
confTimeoutManager = Manager
mgr
, confMySockAddr :: SockAddr
confMySockAddr = SockAddr
mysa
, confPeerSockAddr :: SockAddr
confPeerSockAddr = SockAddr
peersa
}
forall (m :: * -> *) a. Monad m => a -> m a
return Config
config
freeConfigForServer :: Config -> IO ()
freeConfigForServer :: Config -> IO ()
freeConfigForServer Config
conf = forall a. Ptr a -> IO ()
free forall a b. (a -> b) -> a -> b
$ Config -> Ptr Word8
confWriteBuffer Config
conf
allocConfigForClient
:: (ByteString -> IO ()) -> IO ByteString -> SockAddr -> SockAddr -> IO Config
allocConfigForClient :: (ByteString -> IO ())
-> IO ByteString -> SockAddr -> SockAddr -> IO Config
allocConfigForClient ByteString -> IO ()
send IO ByteString
recv SockAddr
mysa SockAddr
peersa = do
let wbufsiz :: Int
wbufsiz = Int
4096
Ptr Word8
buf <- forall a. Int -> IO (Ptr a)
mallocBytes Int
wbufsiz
RecvN
recvN <- ByteString -> IO ByteString -> IO RecvN
makeRecvN ByteString
"" IO ByteString
recv
Manager
mgr <- Int -> IO Manager
T.initialize Int
30000000
let config :: Config
config =
Config
{ confWriteBuffer :: Ptr Word8
confWriteBuffer = Ptr Word8
buf
, confBufferSize :: Int
confBufferSize = Int
wbufsiz
, confSendAll :: ByteString -> IO ()
confSendAll = ByteString -> IO ()
send
, confReadN :: RecvN
confReadN = RecvN
recvN
, confPositionReadMaker :: PositionReadMaker
confPositionReadMaker = PositionReadMaker
defaultPositionReadMaker
, confTimeoutManager :: Manager
confTimeoutManager = Manager
mgr
, confMySockAddr :: SockAddr
confMySockAddr = SockAddr
mysa
, confPeerSockAddr :: SockAddr
confPeerSockAddr = SockAddr
peersa
}
forall (m :: * -> *) a. Monad m => a -> m a
return Config
config
freeConfigForClient :: Config -> IO ()
freeConfigForClient :: Config -> IO ()
freeConfigForClient Config{Int
Ptr Word8
Manager
SockAddr
RecvN
PositionReadMaker
ByteString -> IO ()
confPeerSockAddr :: SockAddr
confMySockAddr :: SockAddr
confTimeoutManager :: Manager
confPositionReadMaker :: PositionReadMaker
confReadN :: RecvN
confSendAll :: ByteString -> IO ()
confBufferSize :: Int
confWriteBuffer :: Ptr Word8
confPeerSockAddr :: Config -> SockAddr
confMySockAddr :: Config -> SockAddr
confTimeoutManager :: Config -> Manager
confPositionReadMaker :: Config -> PositionReadMaker
confReadN :: Config -> RecvN
confSendAll :: Config -> ByteString -> IO ()
confBufferSize :: Config -> Int
confWriteBuffer :: Config -> Ptr Word8
..} = do
forall a. Ptr a -> IO ()
free Ptr Word8
confWriteBuffer
Manager -> IO ()
T.killManager Manager
confTimeoutManager