sendfile 0.7.2 → 0.7.3
raw patch · 5 files changed
+85/−5 lines, 5 files
Files
- sendfile.cabal +4/−2
- src/Network/Socket/SendFile.hs +2/−2
- src/Network/Socket/SendFile/Handle.hs +76/−0
- src/Network/Socket/SendFile/Internal.hs +2/−0
- src/Network/Socket/SendFile/Linux.hsc +1/−1
sendfile.cabal view
@@ -1,5 +1,5 @@ name: sendfile-version: 0.7.2+version: 0.7.3 stability: provisional synopsis: A portable sendfile library description: A library which exposes zero-copy sendfile functionality in a portable way. If a platform does not support sendfile, a fallback implementation in haskell is provided.@@ -22,7 +22,9 @@ library hs-source-dirs: src - exposed-modules: Network.Socket.SendFile, Network.Socket.SendFile.Iter+ exposed-modules: Network.Socket.SendFile+ Network.Socket.SendFile.Iter+ Network.Socket.SendFile.Handle other-modules: Network.Socket.SendFile.Internal
src/Network/Socket/SendFile.hs view
@@ -57,7 +57,7 @@ -- | A more powerful interface than sendFile which accepts a starting offset, and the bytecount to send; the offset and the count must be a positive integer. The initial position of the input file handle matters not since the offset is absolute, and the final position may be different depending on the platform -- no assumptions can be made. sendFile' :: Socket -- ^ The output socket- -> FilePath -- ^ The input file handle+ -> FilePath -- ^ The input file path -> Offset -- ^ The offset to start at -> ByteCount -- ^ The number of bytes to send -> IO ()@@ -69,7 +69,7 @@ sendFileIterWith' :: (IO Iter -> IO a) -> Socket -- ^ The output socket- -> FilePath -- ^ The input file handle+ -> FilePath -- ^ The input file path -> ByteCount -- ^ Maximum bytes to send per block (may send less) -> Offset -- ^ The offset to start at -> ByteCount -- ^ The number of bytes to send
+ src/Network/Socket/SendFile/Handle.hs view
@@ -0,0 +1,76 @@+-- | Handle-based versions of some of the functions exported by+-- Network.Socket.SendFile. +module Network.Socket.SendFile.Handle (+ ByteCount,+ Offset,+ Iter(..), runIter,+ -- * Handle-based sendFiles+ sendFile,+ sendFileIterWith,+ sendFile',+ sendFileIterWith'+ ) where++import System.IO (Handle, hFileSize)++import qualified Network.Socket.SendFile.Internal as Internal+import Network.Socket.SendFile.Iter (Iter(..), runIter)+import Network.Socket.SendFile (ByteCount, Offset)+import Network.Socket (Socket)++-- | Simple sendFile - give it a Socket and a Handle, and it sends the entire+-- file through the socket.+--+-- WARNING: This function will raise 'IOError' 'IllegalOperation'+-- if the 'Handle' is not for an 'Fd'.+sendFile+ :: Socket+ -> Handle+ -> IO ()+sendFile outs inh = do+ count <- hFileSize inh+ Internal.sendFile'' outs inh 0 count++-- | A more interactive version of sendFile, which accepts a callback function+-- in addition to the socket and handle. The callback will be called for each+-- chunk of data the sendFileIterWith function acts on.+--+-- WARNING: This function will raise 'IOError' 'IllegalOperation'+-- if the 'Handle' is not for an 'Fd'.+sendFileIterWith+ :: (IO Iter -> IO a)+ -> Socket+ -> Handle+ -> ByteCount+ -> IO a+sendFileIterWith stepper outs inh blockSize = do+ count <- hFileSize inh+ Internal.sendFileIterWith'' stepper outs inh blockSize 0 count++-- | A sendFile that allows the user to send a subset of the file associated+-- with the given handle.+--+-- WARNING: This function will raise 'IOError' 'IllegalOperation'+-- if the 'Handle' is not for an 'Fd'.+sendFile'+ :: Socket+ -> Handle+ -> Offset+ -> ByteCount+ -> IO ()+sendFile' = Internal.sendFile''++-- | A more powerful version of sendFileIterWith, which allows the sending of a+-- subset of the given file.+--+-- WARNING: This function will raise 'IOError' 'IllegalOperation'+-- if the 'Handle' is not for an 'Fd'.+sendFileIterWith'+ :: (IO Iter -> IO a)+ -> Socket+ -> Handle+ -> ByteCount+ -> Offset+ -> ByteCount+ -> IO a+sendFileIterWith' = Internal.sendFileIterWith''
src/Network/Socket/SendFile/Internal.hs view
@@ -4,6 +4,8 @@ sendFileIterWith, sendFile', sendFileIterWith',+ sendFile'',+ sendFileIterWith'', unsafeSendFile, unsafeSendFileIterWith, unsafeSendFile',
src/Network/Socket/SendFile/Linux.hsc view
@@ -3,7 +3,7 @@ module Network.Socket.SendFile.Linux (_sendFile, sendFileIter, sendfile) where import Data.Int (Int32, Int64)-import Data.Word (Word32, Word64)+import Data.Word (Word32, Word64) -- Word64 is imported on 64-bit systems import Foreign.C.Error (eAGAIN, getErrno, throwErrno) import Foreign.Marshal (alloca) import Foreign.Ptr (Ptr)