This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap-server".

The branch, master has been updated
       via  1307f3516ed5cb83226b84841bf69dd3b1ddfbf8 (commit)
      from  33e83a54fb288f2771fcb42782c4c1f3bdfdb6c9 (commit)


Summary of changes:
 src/Snap/Internal/Http/Server.hs               |   39 ------------------------
 src/Snap/Internal/Http/Server/LibevBackend.hs  |   22 +++++++++----
 src/Snap/Internal/Http/Server/SimpleBackend.hs |   11 ++++--
 3 files changed, 22 insertions(+), 50 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1307f3516ed5cb83226b84841bf69dd3b1ddfbf8
Author: Shu-yu Guo <[email protected]>
Date:   Sun Jun 6 19:30:37 2010 -0700

    Revert previous fix, move ifdefs to backends

diff --git a/src/Snap/Internal/Http/Server.hs b/src/Snap/Internal/Http/Server.hs
index e553a9d..9a4d9ca 100644
--- a/src/Snap/Internal/Http/Server.hs
+++ b/src/Snap/Internal/Http/Server.hs
@@ -176,9 +176,7 @@ httpServe bindAddress bindPort localHostname alogPath 
elogPath handler =
 
             runHTTP localHostname laddr lport raddr rport
                     alog elog readEnd writeEnd
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
                     (Backend.sendFile conn)
-#endif
                     (Backend.tickleTimeout conn) handler
 
             debug "Server.httpServe.runHTTP: finished"
@@ -254,18 +252,12 @@ runHTTP :: ByteString                  -- ^ local host 
name
         -> Maybe Logger                -- ^ error logger
         -> Enumerator IO ()            -- ^ read end of socket
         -> Iteratee IO ()              -- ^ write end of socket
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
         -> (FilePath -> Int -> IO ())  -- ^ sendfile end
-#endif
         -> IO ()                       -- ^ timeout tickler
         -> ServerHandler               -- ^ handler procedure
         -> IO ()
 runHTTP lh lip lp rip rp alog elog
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
         readEnd writeEnd onSendFile tickle handler =
-#else
-        readEnd writeEnd tickle handler =
-#endif
     go `catches` [ Handler $ \(e :: AsyncException) -> do
                        throwIO e
 
@@ -280,11 +272,7 @@ runHTTP lh lip lp rip rp alog elog
     go = do
         buf <- mkIterateeBuffer
         let iter = runServerMonad lh lip lp rip rp (logA alog) (logE elog) $
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
                                   httpSession writeEnd buf onSendFile tickle
-#else
-                                  httpSession writeEnd buf tickle
-#endif
                                   handler
         readEnd iter >>= run
 
@@ -308,17 +296,11 @@ logError s = gets _logError >>= (\l -> liftIO $ l s)
 -- | Runs an HTTP session.
 httpSession :: Iteratee IO ()              -- ^ write end of socket
             -> ForeignPtr CChar            -- ^ iteratee buffer
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
             -> (FilePath -> Int -> IO ())  -- ^ sendfile continuation
-#endif
             -> IO ()                       -- ^ timeout tickler
             -> ServerHandler               -- ^ handler procedure
             -> ServerMonad ()
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
 httpSession writeEnd' ibuf onSendFile tickle handler = do
-#else
-httpSession writeEnd' ibuf tickle handler = do
-#endif
 
     (writeEnd, cancelBuffering) <-
         liftIO $ I.unsafeBufferIterateeWithBuffer ibuf writeEnd'
@@ -358,11 +340,7 @@ httpSession writeEnd' ibuf tickle handler = do
           date <- liftIO getDateString
           let ins = (Map.insert "Date" [date] . Map.insert "Server" 
sERVER_HEADER)
           let rsp' = updateHeaders ins rsp
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
           (bytesSent,_) <- sendResponse rsp' writeEnd ibuf killBuffer 
onSendFile
-#else
-          (bytesSent,_) <- sendResponse rsp' writeEnd ibuf killBuffer
-#endif
 
           liftIO . debug $ "Server.httpSession: sent " ++
                            (Prelude.show bytesSent) ++ " bytes"
@@ -373,11 +351,7 @@ httpSession writeEnd' ibuf tickle handler = do
 
           if cc
              then return ()
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
              else httpSession writeEnd' ibuf onSendFile tickle handler
-#else
-             else httpSession writeEnd' ibuf tickle handler
-#endif
 
       Nothing -> return ()
 
@@ -536,26 +510,15 @@ sendResponse :: Response
              -> Iteratee IO a
              -> ForeignPtr CChar
              -> IO ()
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
              -> (FilePath -> Int -> IO a)
-#endif
              -> ServerMonad (Int, a)
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
 sendResponse rsp' writeEnd ibuf killBuffering onSendFile = do
-#else
-sendResponse rsp' writeEnd ibuf killBuffering = do
-#endif
     rsp <- fixupResponse rsp'
     let !headerString = mkHeaderString rsp
 
     (!x,!bs) <- case (rspBody rsp) of
                   (Enum e)     -> liftIO $ whenEnum headerString e
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
                   (SendFile f) -> liftIO $ whenSendFile headerString rsp f
-#else
-                  (SendFile f) -> liftIO $ whenEnum headerString
-                                                    (I.enumFile f)
-#endif
 
     return $! (bs,x)
 
@@ -568,7 +531,6 @@ sendResponse rsp' writeEnd ibuf killBuffering = do
 
         return (x, bs-hl)
 
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
     whenSendFile hs r f = do
         -- guaranteed to have a content length here.
         enumBS hs writeEnd >>= run
@@ -576,7 +538,6 @@ sendResponse rsp' writeEnd ibuf killBuffering = do
         let !cl = fromJust $ rspContentLength r
         x <- onSendFile f cl
         return (x, cl)
-#endif
 
     (major,minor) = rspHttpVersion rsp'
 
diff --git a/src/Snap/Internal/Http/Server/LibevBackend.hs 
b/src/Snap/Internal/Http/Server/LibevBackend.hs
index 177f51f..7fdfd0e 100644
--- a/src/Snap/Internal/Http/Server/LibevBackend.hs
+++ b/src/Snap/Internal/Http/Server/LibevBackend.hs
@@ -18,9 +18,7 @@ module Snap.Internal.Http.Server.LibevBackend
   , new
   , stop
   , withConnection
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
   , sendFile
-#endif
   , tickleTimeout
   , getReadEnd
   , getWriteEnd
@@ -63,7 +61,7 @@ import           System.Timeout
 import           Snap.Iteratee
 import           Snap.Internal.Debug
 
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
+#if defined(HAS_SENDFILE)
 import qualified System.SendFile as SF
 import           System.Posix.IO
 import           System.Posix.Types (Fd(..))
@@ -117,17 +115,26 @@ name :: ByteString
 name = "libev"
 
 
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
 sendFile :: Connection -> FilePath -> Int -> IO ()
-sendFile c fp total = do
+#if defined(HAS_SENDFILE)
+sendFile c fp sz = do
+#else
+sendFile c fp _ = do
+#endif
     withMVar lock $ \_ -> do
       act <- readIORef $ _writeActive c
       when act $ evIoStop loop io
       writeIORef (_writeActive c) False
       evAsyncSend loop asy
 
+#if defined(HAS_SENDFILE)
     fd <- openFd fp ReadOnly Nothing defaultFileFlags
-    go fd 0 total
+    go fd 0 sz
+#else
+    -- no need to count bytes
+    enumFile fp (getWriteEnd c) >>= run
+    return ()
+#endif
 
     withMVar lock $ \_ -> do
       tryTakeMVar $ _readAvailable c
@@ -135,6 +142,7 @@ sendFile c fp total = do
       evAsyncSend loop asy
 
   where
+#if defined(HAS_SENDFILE)
     go fd off bytes
       | bytes == 0 = return ()
       | otherwise  = do
@@ -144,12 +152,12 @@ sendFile c fp total = do
               else return ()
 
     sfd  = Fd $ _socketFd c
+#endif
     io   = _connWriteIOObj c
     b    = _backend c
     loop = _evLoop b
     lock = _loopLock b
     asy  = _asyncObj b
-#endif
 
 
 bindIt :: ByteString         -- ^ bind address, or \"*\" for all
diff --git a/src/Snap/Internal/Http/Server/SimpleBackend.hs 
b/src/Snap/Internal/Http/Server/SimpleBackend.hs
index 41a7cdd..b54d867 100644
--- a/src/Snap/Internal/Http/Server/SimpleBackend.hs
+++ b/src/Snap/Internal/Http/Server/SimpleBackend.hs
@@ -18,9 +18,7 @@ module Snap.Internal.Http.Server.SimpleBackend
   , new
   , stop
   , withConnection
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
   , sendFile
-#endif
   , tickleTimeout
   , getReadEnd
   , getWriteEnd
@@ -57,7 +55,7 @@ import           Snap.Internal.Debug
 import           Snap.Internal.Http.Server.Date
 import           Snap.Iteratee hiding (foldl')
 
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
+#if defined(HAS_SENDFILE)
 import qualified System.SendFile as SF
 import           System.Posix.IO
 import           System.Posix.Types (Fd(..))
@@ -93,8 +91,8 @@ name :: ByteString
 name = "simple"
 
 
-#if defined(HAS_SENDFILE) && !defined(PORTABLE)
 sendFile :: Connection -> FilePath -> Int -> IO ()
+#if defined(HAS_SENDFILE)
 sendFile c fp sz = do
     fd <- openFd fp ReadOnly Nothing defaultFileFlags
     go fd 0 sz
@@ -108,6 +106,11 @@ sendFile c fp sz = do
               else return ()
 
     sfd = Fd . fdSocket $ _socket c
+#else
+sendFile c fp _ = do
+    -- no need to count bytes
+    enumFile fp (getWriteEnd c) >>= run
+    return ()
 #endif
 
 
-----------------------------------------------------------------------


hooks/post-receive
-- 
snap-server
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to