on master help sign in
moving types to Types.
commit2d425c8c43ebe768dfa2df24547c094f87a97ee7 authorKazu Yamamoto <kazu@iij.ad.jp> dateTue 16 Jun 2015, 16:27 (11 years ago) parent2f8a8e1
5 files changed+15−15
warp/Network/Wai/Handler/Warp/Buffer.hs+7−11 warp/Network/Wai/Handler/Warp/IO.hs+1−1 warp/Network/Wai/Handler/Warp/Recv.hs+1 warp/Network/Wai/Handler/Warp/SendFile.hs−1 warp/Network/Wai/Handler/Warp/Types.hs+6−2
warp/Network/Wai/Handler/Warp/Buffer.hs+7−11
@@ -1,23 +1,22 @@
11module Network.Wai.Handler.Warp.Buffer where
22
33import Control.Monad (when)
4−import qualified Data.Streaming.ByteString.Builder.Buffer as B (Buffer (..))
5−import Data.Word (Word8)
6−import Data.IORef (IORef, newIORef, readIORef, writeIORef)
74import Data.ByteString (ByteString, empty, length)
85import Data.ByteString.Internal (ByteString(PS), mallocByteString)
96import Data.ByteString.Unsafe (unsafeTake, unsafeDrop)
7+import Data.IORef (newIORef, readIORef, writeIORef)
8+import qualified Data.Streaming.ByteString.Builder.Buffer as B (Buffer (..))
109import Foreign.ForeignPtr (newForeignPtr, newForeignPtr_, withForeignPtr)
1110import Foreign.Marshal.Alloc (mallocBytes, free, finalizerFree)
12−import Foreign.Ptr (Ptr, castPtr, plusPtr)
11+import Foreign.Ptr (castPtr, plusPtr)
12+import Network.Wai.Handler.Warp.Types
1313
1414largeBufferSize :: Int
1515largeBufferSize = 16384
16+
1617minBufferSize :: Int
1718minBufferSize = 2048
1819
19−type BufferPool = IORef ByteString
20−
2120newBufferPool :: IO BufferPool
2221newBufferPool = newIORef Data.ByteString.empty
2322
@@ -48,11 +47,11 @@ putBuffer :: BufferPool -> ByteString -> IO ()
4847putBuffer pool buffer = when (usefulBuffer buffer) $ writeIORef pool buffer
4948{-# INLINE putBuffer #-}
5049
51−withForeignBuffer :: ByteString -> ((Ptr Word8, Int) -> IO Int) -> IO Int
50+withForeignBuffer :: ByteString -> ((Buffer, BufSize) -> IO Int) -> IO Int
5251withForeignBuffer (PS ps s l) f = withForeignPtr ps $ \p -> f (castPtr p `plusPtr` s, l)
5352{-# INLINE withForeignBuffer #-}
5453
55−withBufferPool :: BufferPool -> ((Ptr Word8, Int) -> IO Int) -> IO ByteString
54+withBufferPool :: BufferPool -> ((Buffer, BufSize) -> IO Int) -> IO ByteString
5655withBufferPool pool f = do
5756 buffer <- getBuffer pool
5857 consumed <- withForeignBuffer buffer f
@@ -60,9 +59,6 @@ withBufferPool pool f = do
6059 return $! unsafeTake consumed buffer
6160{-# INLINE withBufferPool #-}
6261
63−type Buffer = Ptr Word8
64−type BufSize = Int
65−
6662-- 2^14 = 1024 * 16
6763-- The maximum size of TLS record
6864-- The maximum size of HTTP/2 frame payload (excluding frame header)
warp/Network/Wai/Handler/Warp/IO.hs+1−1
@@ -5,7 +5,7 @@ module Network.Wai.Handler.Warp.IO where
55
66import Data.ByteString.Internal (ByteString(..))
77import Foreign.ForeignPtr (newForeignPtr_)
8−import Network.Wai.Handler.Warp.Buffer
8+import Network.Wai.Handler.Warp.Types
99
1010-- Support for doctest, where cabal macros are not available
1111#ifndef MIN_VERSION_blaze_builder
warp/Network/Wai/Handler/Warp/Recv.hs+1
@@ -15,6 +15,7 @@ import Foreign.C.Types
1515import Foreign.Ptr (Ptr, castPtr)
1616import GHC.Conc (threadWaitRead)
1717import Network.Socket (Socket, fdSocket)
18+import Network.Wai.Handler.Warp.Types
1819import Network.Wai.Handler.Warp.Buffer
1920import System.Posix.Types (Fd(..))
2021
warp/Network/Wai/Handler/Warp/SendFile.hs−1
@@ -10,7 +10,6 @@ import Data.ByteString.Internal
1010import Foreign.ForeignPtr (newForeignPtr_, withForeignPtr)
1111import Network.Sendfile
1212import Network.Socket (Socket)
13−import Network.Wai.Handler.Warp.Buffer
1413import Network.Wai.Handler.Warp.Types
1514
1615#ifdef WINDOWS
warp/Network/Wai/Handler/Warp/Types.hs+6−2
@@ -9,9 +9,9 @@ import Data.ByteString (ByteString)
99import qualified Data.ByteString as S
1010import Data.IORef (IORef, readIORef, writeIORef, newIORef)
1111import Data.Typeable (Typeable)
12−import Data.Word (Word16)
12+import Data.Word (Word16, Word8)
13+import Foreign.Ptr (Ptr)
1314import Network.HTTP.Types.Header
14−import Network.Wai.Handler.Warp.Buffer (Buffer,BufSize,BufferPool)
1515import qualified Network.Wai.Handler.Warp.Date as D
1616import qualified Network.Wai.Handler.Warp.FdCache as F
1717import qualified Network.Wai.Handler.Warp.Timeout as T
@@ -79,6 +79,10 @@ data FileId = FileId {
7979-- | fileid, offset, length, hook action, HTTP headers
8080type SendFile = FileId -> Integer -> Integer -> IO () -> [ByteString] -> IO ()
8181
82+type BufferPool = IORef ByteString
83+type Buffer = Ptr Word8
84+type BufSize = Int
85+
8286-- | Data type to manipulate IO actions for connections.
8387data Connection = Connection
8488 { connSendMany :: [ByteString] -> IO ()