packages feed

http2 2.0.0 → 2.0.1

raw patch · 5 files changed

+57/−24 lines, 5 files

Files

ChangeLog.md view
@@ -1,3 +1,9 @@+## 2.0.1++* Bug fix for defaultReadN.+* Providing allocSimpleConfig and freeSimpleConfig.+* Deprecating makeSimpleConfig.+ ## 2.0.0  * Providing Network.HTTP.Server.
Network/HTTP2/Server.hs view
@@ -17,37 +17,46 @@ -- > import Network.Socket -- > -- > main :: IO ()--- > main = withSocketsDo $ do--- >     addr <- resolve "80"--- >     E.bracket (open addr) close loop+-- > main = runTCPServer "80" $ \s _peer -> runHTTP2Server s -- >   where--- >     server _req _ctl sendResponse = sendResponse response []+-- >     runHTTP2Server s = E.bracket (allocSimpleConfig s 4096)+-- >                                  (\config -> run config server)+-- >                                  freeSimpleConfig+-- >     server _req _aux sendResponse = sendResponse response [] -- >       where--- >         response = responseBuilder ok200 [("Content-Type", "text/plain")] (byteString "Hello, world!\n")--- >     loop sock = forever $ do--- >         (s, _peer) <- accept sock--- >         (config, cleanup) <- makeSimpleConfig s 4096--- >         void $ forkFinally (run config server) (\_ -> close s >> cleanup)--- >     resolve port = do+-- >         response = responseBuilder ok200 header body+-- >         header = [("Content-Type", "text/plain")]+-- >         body = byteString "Hello, world!\n"+-- >+-- > runTCPServer :: String -> (Socket -> SockAddr -> IO a) -> IO a+-- > runTCPServer port server = withSocketsDo $ do+-- >     addr <- resolve+-- >     E.bracket (open addr) close loop+-- >   where+-- >     resolve = do -- >         let hints = defaultHints { -- >                 addrFlags = [AI_PASSIVE] -- >               , addrSocketType = Stream -- >               }--- >         addr:_ <- getAddrInfo (Just hints) Nothing (Just port)--- >         return addr+-- >         head <$> getAddrInfo (Just hints) Nothing (Just port) -- >     open addr = do -- >         sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) -- >         setSocketOption sock ReuseAddr 1 -- >         withFdSocket sock $ setCloseOnExecIfNeeded--- >         bind sock (addrAddress addr)--- >         listen sock 10+-- >         bind sock $ addrAddress addr+-- >         listen sock 1024 -- >         return sock+-- >     loop sock = forever $ do+-- >         (conn, peer) <- accept sock+-- >         void $ forkFinally (server conn peer) (\_ -> close conn)  module Network.HTTP2.Server (   -- * Runner     run   -- * Runner arguments   , Config(..)+  , allocSimpleConfig+  , freeSimpleConfig   , makeSimpleConfig   -- * HTTP/2 server   , Server@@ -101,7 +110,7 @@ import Imports import Network.HPACK import Network.HTTP2.Server.API-import Network.HTTP2.Server.Config (makeSimpleConfig)+import Network.HTTP2.Server.Config import Network.HTTP2.Server.File (defaultPositionReadMaker) import Network.HTTP2.Server.ReadN (defaultReadN) import Network.HTTP2.Server.Run (run)
Network/HTTP2/Server/Config.hs view
@@ -10,11 +10,19 @@ import Network.HTTP2.Server.File import Network.HTTP2.Server.ReadN +{-# DEPRECATED makeSimpleConfig "Use allocSimpleConfig instead" #-} -- | Making configuration whose IO is not efficient. --   A write buffer is allocated internally. --   That should be deallocated by the returned action. makeSimpleConfig :: Socket -> BufferSize -> IO (Config, IO ()) makeSimpleConfig s bufsiz = do+    config <- allocSimpleConfig s bufsiz+    return (config, freeSimpleConfig config)++-- | Making simple configuration whose IO is not efficient.+--   A write buffer is allocated internally.+allocSimpleConfig :: Socket -> BufferSize -> IO Config+allocSimpleConfig s bufsiz = do     buf <- mallocBytes bufsiz     ref <- newIORef Nothing     let config = Config {@@ -24,4 +32,8 @@           , confReadN = defaultReadN s ref           , confPositionReadMaker = defaultPositionReadMaker           }-    return (config, free buf)+    return config++-- | Deallocating the resource of the simple configuration.+freeSimpleConfig :: Config -> IO ()+freeSimpleConfig conf = free $ confWriteBuffer conf
Network/HTTP2/Server/ReadN.hs view
@@ -7,13 +7,16 @@  -- | Naive implementation for readN. defaultReadN :: Socket -> IORef (Maybe B.ByteString) -> Int -> IO B.ByteString+defaultReadN _ _   0 = return B.empty defaultReadN s ref n = do     mbs <- readIORef ref     writeIORef ref Nothing     case mbs of       Nothing -> do           bs <- N.recv s n-          if B.length bs == n then+          if B.null bs then+              return B.empty+          else if B.length bs == n then               return bs             else               loop bs@@ -28,8 +31,11 @@     loop bs = do         let n' = n - B.length bs         bs1 <- N.recv s n'-        let bs2 = bs `B.append` bs1-        if B.length bs2 == n then-            return bs2-          else-            loop bs2+        if B.null bs1 then+            return B.empty+          else do+            let bs2 = bs `B.append` bs1+            if B.length bs2 == n then+                return bs2+              else+                loop bs2
http2.cabal view
@@ -1,5 +1,5 @@ Name:                   http2-Version:                2.0.0+Version:                2.0.1 Author:                 Kazu Yamamoto <kazu@iij.ad.jp> Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp> License:                BSD3@@ -102,7 +102,7 @@                       , containers >= 0.5                       , http-types                       , network-                      , network-byte-order+                      , network-byte-order >= 0.1.1                       , psqueues                       , stm                       , time-manager