Permalink
Browse files

implementing fallback.

  • Loading branch information...
1 parent f04e245 commit 9aa552556d78e6348657cfd118bf75431d3aec6f @kazu-yamamoto committed Jun 21, 2012
Showing with 20 additions and 9 deletions.
  1. +20 −9 Network/Sendfile/Fallback.hs
View
29 Network/Sendfile/Fallback.hs
@@ -9,18 +9,20 @@ import Data.Conduit
import Data.Conduit.Binary as EB
import Network.Sendfile.Types
import Network.Socket
+import Network.Socket.ByteString
import qualified Network.Socket.ByteString as SB
-{-|
- Sendfile emulation using conduit.
+-- |
+-- Sendfile emulation using conduit.
+-- Used system calls:
+--
+-- - Used system calls: open(), stat(), read(), send() and close().
- - Used system calls: open(), stat(), read(), send() and close().
--}
sendfile :: Socket -> FilePath -> FileRange -> IO () -> IO ()
-sendfile s fp EntireFile hook =
- runResourceT $ sourceFile fp $$ sinkSocket s hook
-sendfile s fp (PartOfFile off len) hook =
- runResourceT $ EB.sourceFileRange fp (Just off) (Just len) $$ sinkSocket s hook
+sendfile sock path EntireFile hook =
+ runResourceT $ sourceFile path $$ sinkSocket sock hook
+sendfile sock path (PartOfFile off len) hook =
+ runResourceT $ EB.sourceFileRange path (Just off) (Just len) $$ sinkSocket sock hook
-- See sinkHandle.
sinkSocket :: MonadIO m => Socket -> IO () -> Sink ByteString m ()
@@ -32,5 +34,14 @@ sinkSocket s hook = NeedInput push close
return (NeedInput push close)
close = return ()
+-- |
+-- Sendfile emulation using conduit.
+-- Used system calls:
+--
+-- - Used system calls: open(), stat(), read(), writev(), send() and close().
+
sendfileWithHeader :: Socket -> FilePath -> FileRange -> IO () -> [ByteString] -> IO ()
-sendfileWithHeader = undefined
+sendfileWithHeader sock path range hook hdr = do
+ sendMany sock hdr
+ hook
+ sendfile sock path range hook

0 comments on commit 9aa5525

Please sign in to comment.