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 fa81e0ae22ad1747003b9a668f536676835ffaba (commit)
from 434c460e6604765516effb3a44c12d60074e69dc (commit)
Summary of changes:
src/Snap/Internal/Http/Server/LibevBackend.hs | 2 +-
src/Snap/Internal/Http/Server/SimpleBackend.hs | 3 +-
src/System/SendFile/Darwin.hsc | 18 +++++++----
src/System/SendFile/FreeBSD.hsc | 36 ++++++++++++++----------
src/System/SendFile/Linux.hsc | 14 ++++----
5 files changed, 42 insertions(+), 31 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 fa81e0ae22ad1747003b9a668f536676835ffaba
Author: Gregory Collins <[email protected]>
Date: Sun Jun 12 15:33:23 2011 -0400
Make sendfile block if the write buffer is full: closes #53
diff --git a/src/Snap/Internal/Http/Server/LibevBackend.hs
b/src/Snap/Internal/Http/Server/LibevBackend.hs
index 4376a46..795c1b1 100644
--- a/src/Snap/Internal/Http/Server/LibevBackend.hs
+++ b/src/Snap/Internal/Http/Server/LibevBackend.hs
@@ -662,7 +662,7 @@ sendFile defaultTimeout c s fp start sz = do
go off bytes fd
| bytes == 0 = return ()
| otherwise = do
- sent <- SF.sendFile sfd fd off bytes
+ sent <- SF.sendFile (waitForLock False c) sfd fd off bytes
if sent < bytes
then tickleTimeout c defaultTimeout >>
go (off+sent) (bytes-sent) fd
diff --git a/src/Snap/Internal/Http/Server/SimpleBackend.hs
b/src/Snap/Internal/Http/Server/SimpleBackend.hs
index 0175ada..fdaf87d 100644
--- a/src/Snap/Internal/Http/Server/SimpleBackend.hs
+++ b/src/Snap/Internal/Http/Server/SimpleBackend.hs
@@ -220,7 +220,8 @@ sendFile lsock tickle sock writeEnd fp start sz =
go off bytes fd
| bytes == 0 = return ()
| otherwise = do
- sent <- SF.sendFile sfd fd off bytes
+ sent <- SF.sendFile (threadWaitWrite $ fromIntegral fd)
+ sfd fd off bytes
if sent < bytes
then tickle >> go (off+sent) (bytes-sent) fd
else return ()
diff --git a/src/System/SendFile/Darwin.hsc b/src/System/SendFile/Darwin.hsc
index 6459962..8534948 100644
--- a/src/System/SendFile/Darwin.hsc
+++ b/src/System/SendFile/Darwin.hsc
@@ -10,23 +10,26 @@ import Foreign.Ptr (Ptr, nullPtr)
import Foreign.Storable (peek, poke)
import System.Posix.Types (Fd, COff)
-sendFile :: Fd -> Fd -> Int64 -> Int64 -> IO Int64
-sendFile out_fd in_fd off count
+sendFile :: IO () -> Fd -> Fd -> Int64 -> Int64 -> IO Int64
+sendFile onBlock out_fd in_fd off count
| count == 0 = return 0
| otherwise = alloca $ \pbytes -> do
poke pbytes $ min maxBytes (fromIntegral count)
- sbytes <- sendfile out_fd in_fd (fromIntegral off) pbytes
+ sbytes <- sendfile onBlock out_fd in_fd (fromIntegral off) pbytes
return $ fromIntegral sbytes
-sendfile :: Fd -> Fd -> COff -> Ptr COff -> IO COff
-sendfile out_fd in_fd off pbytes = do
+sendfile :: IO () -> Fd -> Fd -> COff -> Ptr COff -> IO COff
+sendfile onBlock out_fd in_fd off pbytes = do
status <- c_sendfile out_fd in_fd off pbytes
nsent <- peek pbytes
if status == 0
then return nsent
else do errno <- getErrno
if (errno == eAGAIN) || (errno == eINTR)
- then return nsent
+ then do
+ if nsent == 0
+ then onBlock >> sendfile onBlock out_fd in_fd off pbytes
+ else return nsent
else throwErrno "System.SendFile.Darwin"
-- max num of bytes in one send
@@ -38,4 +41,5 @@ foreign import ccall unsafe "sys/uio.h sendfile"
c_sendfile_darwin
:: Fd -> Fd -> COff -> Ptr COff -> Ptr () -> CInt -> IO CInt
c_sendfile :: Fd -> Fd -> COff -> Ptr COff -> IO CInt
-c_sendfile out_fd in_fd off pbytes = c_sendfile_darwin in_fd out_fd off pbytes
nullPtr 0
+c_sendfile out_fd in_fd off pbytes =
+ c_sendfile_darwin in_fd out_fd off pbytes nullPtr 0
diff --git a/src/System/SendFile/FreeBSD.hsc b/src/System/SendFile/FreeBSD.hsc
index 09f881c..d57eaee 100644
--- a/src/System/SendFile/FreeBSD.hsc
+++ b/src/System/SendFile/FreeBSD.hsc
@@ -11,25 +11,31 @@ import Foreign.Ptr (Ptr, nullPtr)
import Foreign.Storable (peek)
import System.Posix.Types (COff, Fd)
-sendFile :: Fd -> Fd -> Int64 -> Int64 -> IO Int64
-sendFile out_fd in_fd off count
+sendFile :: IO () -> Fd -> Fd -> Int64 -> Int64 -> IO Int64
+sendFile onBlock out_fd in_fd off count
| count == 0 = return 0
| otherwise = alloca $ \pbytes -> do
- sbytes <- sendfile out_fd in_fd (fromIntegral off)
- (fromIntegral count) pbytes
+ sbytes <- sendfile onBlock out_fd in_fd
+ (fromIntegral off)
+ (fromIntegral count)
+ pbytes
return $ fromIntegral sbytes
-sendfile :: Fd -> Fd -> COff -> CSize -> Ptr COff -> IO COff
-sendfile out_fd in_fd off count pbytes =
- do threadWaitWrite out_fd
- res <- c_sendfile_freebsd in_fd out_fd off count nullPtr pbytes 0
- nsent <- peek pbytes
- if (res == 0)
- then return nsent
- else do errno <- getErrno
- if (errno == eAGAIN) || (errno == eINTR)
- then return nsent
- else throwErrno "System.SendFile.FreeBSD.sendfile"
+sendfile :: IO () -> Fd -> Fd -> COff -> CSize -> Ptr COff -> IO COff
+sendfile onBlock out_fd in_fd off count pbytes = do
+ res <- c_sendfile_freebsd in_fd out_fd off count nullPtr pbytes 0
+ nsent <- peek pbytes
+ if (res == 0)
+ then return nsent
+ else do
+ errno <- getErrno
+ if (errno == eAGAIN) || (errno == eINTR)
+ then if nsent == 0
+ then do
+ onBlock
+ sendfile onBlock out_fd in_fd off count pbytes
+ else return nsent
+ else throwErrno "System.SendFile.FreeBSD.sendfile"
-- max num of bytes in one send
maxBytes :: CSize
diff --git a/src/System/SendFile/Linux.hsc b/src/System/SendFile/Linux.hsc
index 4e437ac..64784cc 100644
--- a/src/System/SendFile/Linux.hsc
+++ b/src/System/SendFile/Linux.hsc
@@ -10,26 +10,26 @@ import Foreign.Ptr (Ptr, nullPtr)
import Foreign.Storable (poke)
import System.Posix.Types (Fd, COff, CSsize)
-sendFile :: Fd -> Fd -> Int64 -> Int64 -> IO Int64
-sendFile out_fd in_fd off count
+sendFile :: IO () -> Fd -> Fd -> Int64 -> Int64 -> IO Int64
+sendFile onBlock out_fd in_fd off count
| count == 0 = return 0
| off == 0 = do
- sbytes <- sendfile out_fd in_fd nullPtr bytes
+ sbytes <- sendfile onBlock out_fd in_fd nullPtr bytes
return $ fromIntegral sbytes
| otherwise = alloca $ \poff -> do
poke poff (fromIntegral off)
- sbytes <- sendfile out_fd in_fd poff bytes
+ sbytes <- sendfile onBlock out_fd in_fd poff bytes
return $ fromIntegral sbytes
where
bytes = min (fromIntegral count) maxBytes
-sendfile :: Fd -> Fd -> Ptr COff -> CSize -> IO CSsize
-sendfile out_fd in_fd poff bytes = do
+sendfile :: IO () -> Fd -> Fd -> Ptr COff -> CSize -> IO CSsize
+sendfile onBlock out_fd in_fd poff bytes = do
nsent <- c_sendfile out_fd in_fd poff bytes
if nsent <= -1
then do errno <- getErrno
if errno == eAGAIN
- then sendfile out_fd in_fd poff bytes
+ then onBlock >> sendfile out_fd in_fd poff bytes
else throwErrno "System.SendFile.Linux"
else return nsent
-----------------------------------------------------------------------
hooks/post-receive
--
snap-server
_______________________________________________
Snap mailing list
[email protected]
https://mailman-mail5.webfaction.com/listinfo/snap