on master help sign in
using newtype for MutableFdCache for cleaner API.
commitc6995912c0deb679c129aed0e6cd8641a52951c5 authorKazu Yamamoto <kazu@iij.ad.jp> dateFri 18 Dec 2015, 09:37 (11 years ago) parent62b47ca
1 file changed+7−7
warp/Network/Wai/Handler/Warp/FdCache.hs+7−7
warp/Network/Wai/Handler/Warp/FdCache.hs+7−7
@@ -69,10 +69,10 @@ type Hash = Int
6969type FdCache = MMap Hash FdEntry
7070
7171-- | Mutable Fd cacher.
72−type MutableFdCache = Reaper FdCache (Hash, FdEntry)
72+newtype MutableFdCache = MutableFdCache (Reaper FdCache (Hash, FdEntry))
7373
7474fdCache :: MutableFdCache -> IO FdCache
75−fdCache mfc = reaperRead mfc
75+fdCache (MutableFdCache reaper) = reaperRead reaper
7676
7777look :: MutableFdCache -> FilePath -> Hash -> IO (Maybe FdEntry)
7878look mfc path key = searchWith key check <$> fdCache mfc
@@ -98,7 +98,7 @@ withFdCache duration action = bracket (initialize duration)
9898-- The first argument is a cache duration in second.
9999initialize :: Int -> IO (Maybe MutableFdCache)
100100initialize 0 = return Nothing
101−initialize duration = Just <$> mkReaper defaultReaperSettings
101+initialize duration = Just . MutableFdCache <$> mkReaper defaultReaperSettings
102102 { reaperAction = clean
103103 , reaperDelay = duration
104104 , reaperCons = uncurry insert
@@ -131,8 +131,8 @@ prune k (Tom ent@(FdEntry _ fd mst) vs) = status mst >>= prune'
131131
132132terminate :: Maybe MutableFdCache -> IO ()
133133terminate Nothing = return ()
134−terminate (Just mfc) = do
135− !t <- reaperStop mfc
134+terminate (Just (MutableFdCache reaper)) = do
135+ !t <- reaperStop reaper
136136 mapM_ closeIt $ toList t
137137 where
138138 closeIt (_, FdEntry _ fd _) = closeFd fd
@@ -141,12 +141,12 @@ terminate (Just mfc) = do
141141
142142-- | Getting 'Fd' and 'Refresh' from the mutable Fd cacher.
143143getFd :: MutableFdCache -> FilePath -> IO (Fd, Refresh)
144−getFd mfc path = look mfc path key >>= getFd'
144+getFd mfc@(MutableFdCache reaper) path = look mfc path key >>= getFd'
145145 where
146146 key = hash path
147147 getFd' Nothing = do
148148 ent@(FdEntry _ fd mst) <- newFdEntry path
149− reaperAdd mfc (key, ent)
149+ reaperAdd reaper (key, ent)
150150 return (fd, refresh mst)
151151 getFd' (Just (FdEntry _ fd mst)) = do
152152 refresh mst