on master help sign in
Added cancel to Timeout
commitdbfb7505258ff7ef079f93bc91d81aee4fc51a90 authorMichael Snoyman <michael@snoyman.com> dateSun 6 Feb 2011, 17:18 (16 years ago) parent04d6c1d
2 files changed+8−2
Network/Wai/Handler/Warp.hs+1 Timeout.hs+7−2
Network/Wai/Handler/Warp.hs+1
@@ -152,6 +152,7 @@ serveConnections' set app socket = do
152152 _ <- forkIO $ do
153153 th <- T.register tm $ sClose conn
154154 serveConnection th onE port app conn sa
155+ T.cancel th
155156 return ()
156157
157158serveConnection :: T.Handle
Timeout.hs+7−2
@@ -6,6 +6,7 @@ module Timeout
66 , tickle
77 , pause
88 , resume
9+ , cancel
910 ) where
1011
1112import qualified Data.IORef as I
@@ -13,9 +14,11 @@ import Control.Concurrent (forkIO, threadDelay)
1314import Control.Monad (forever)
1415import qualified Control.Exception as E
1516
17+-- FIXME implement stopManager
18+
1619newtype Manager = Manager (I.IORef [Handle])
1720data Handle = Handle (IO ()) (I.IORef State)
18−data State = Active | Inactive | Paused
21+data State = Active | Inactive | Paused | Canceled
1922
2023initialize :: Int -> IO Manager
2124initialize timeout = do
@@ -34,6 +37,7 @@ initialize timeout = do
3437 Inactive -> do
3538 onTimeout `E.catch` ignoreAll
3639 go rest front
40+ Canceled -> go rest front
3741 _ -> go rest (front . (:) m)
3842 go' Active = Inactive
3943 go' x = x
@@ -48,7 +52,8 @@ register (Manager ref) onTimeout = do
4852 I.atomicModifyIORef ref (\x -> (h : x, ()))
4953 return h
5054
51−tickle, pause, resume :: Handle -> IO ()
55+tickle, pause, resume, cancel :: Handle -> IO ()
5256tickle (Handle _ iactive) = I.writeIORef iactive Active
5357pause (Handle _ iactive) = I.writeIORef iactive Paused
5458resume = tickle
59+cancel (Handle _ iactive) = I.writeIORef iactive Canceled