sendfile 0.3 → 0.3.1
raw patch · 7 files changed
+23/−18 lines, 7 files
Files
- csrc/sendfile_win32.c +0/−1
- sendfile.cabal +1/−1
- src/Network/Socket/SendFile.hs +1/−1
- src/Network/Socket/SendFile/Internal.hs +9/−3
- src/Network/Socket/SendFile/Linux.hsc +4/−4
- src/Network/Socket/SendFile/Portable.hs +3/−3
- src/Network/Socket/SendFile/Win32.hsc +5/−5
csrc/sendfile_win32.c view
@@ -14,4 +14,3 @@ /* http://msdn.microsoft.com/en-us/library/ks2530z6.aspx */ return _get_osfhandle(fd); }-
sendfile.cabal view
@@ -1,5 +1,5 @@ name: sendfile-version: 0.3+version: 0.3.1 stability: experimental 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.
src/Network/Socket/SendFile.hs view
@@ -16,7 +16,7 @@ -> IO () sendFile = Network.Socket.SendFile.Internal.sendFile --- | A more powerful interface than sendFile, sendFile' accepts a `Handle` for the input file instead of a `FilePath` and the number of bytes you would like to read. This unlocks the full potential `Handle`(s). For instance, if you wanted to start reading from a particular offset, you could utilize `hSeek`. If you need the file size you can use 'hFileSize'.+-- | A more powerful interface than sendFile, sendFile' accepts a `Handle` for the input file instead of a `FilePath` and the number of bytes you would like to read; this number must be a positive integer. This unlocks the full potential `Handle`(s). For instance, if you wanted to start reading from a particular offset, you could utilize `hSeek`. If you need the file size you can use 'hFileSize'. sendFile' :: Handle -- ^ The output handle -> Handle -- ^ The input handle -> Integer -- ^ The number of bytes to read
src/Network/Socket/SendFile/Internal.hs view
@@ -13,21 +13,21 @@ ) #if defined(WIN32_SENDFILE)-import Network.Socket.SendFile.Win32 (sendFile')+import Network.Socket.SendFile.Win32 (_sendFile) sendFileMode :: String sendFileMode = "WIN32_SENDFILE" #endif #if defined(LINUX_SENDFILE)-import Network.Socket.SendFile.Linux (sendFile')+import Network.Socket.SendFile.Linux (_sendFile) sendFileMode :: String sendFileMode = "LINUX_SENDFILE" #endif #if defined(PORTABLE_SENDFILE)-import Network.Socket.SendFile.Portable (sendFile')+import Network.Socket.SendFile.Portable (_sendFile) sendFileMode :: String sendFileMode = "PORTABLE_SENDFILE"@@ -37,3 +37,9 @@ sendFile outp infp = withBinaryFile infp ReadMode $ \inp -> do count <- hFileSize inp sendFile' outp inp count++sendFile' :: Handle -> Handle -> Integer -> IO ()+sendFile' outp inp count+ | count < 0 = error "sendFile' - count must be a positive integer"+ | count == 0 = return () -- Send nothing -- why do the work? Also, Windows treats '0' as 'send the whole file'.+ | otherwise = _sendFile outp inp count
src/Network/Socket/SendFile/Linux.hsc view
@@ -1,6 +1,6 @@ {-# LANGUAGE ForeignFunctionInterface #-} -- | Linux system-dependent code for 'sendfile'. -module Network.Socket.SendFile.Linux (sendFile') where+module Network.Socket.SendFile.Linux (_sendFile) where import Data.Int import Data.Word import Foreign.C.Error (throwErrno) @@ -10,8 +10,8 @@ #include <sys/sendfile.h> -sendFile' :: Handle -> Handle -> Integer -> IO () -sendFile' outp inp count = do +_sendFile :: Handle -> Handle -> Integer -> IO () +_sendFile outp inp count = do -- flush outp before sending hFlush outp withHandle_ "Network.Socket.SendFile.Linux.sendFile'" outp $ \outp' -> do @@ -23,5 +23,5 @@ then throwErrno "Network.Socket.SendFile.Linux.sendFile'" else return () -foreign import ccall +foreign import ccall unsafe c_sendfile_linux :: FD -> FD -> (#type size_t) -> IO (#type ssize_t)
src/Network/Socket/SendFile/Portable.hs view
@@ -1,5 +1,5 @@ -- | Portable implementation of sendfile. -module Network.Socket.SendFile.Portable (sendFile') where +module Network.Socket.SendFile.Portable (_sendFile) where import Data.ByteString.Char8 import Prelude hiding (readFile) @@ -7,7 +7,7 @@ -- FIXME: possibly immature / inefficient implementation -sendFile' :: Handle -> Handle -> Integer -> IO () -sendFile' outp inp count = do +_sendFile :: Handle -> Handle -> Integer -> IO () +_sendFile outp inp count = do hPutStr outp =<< hGet inp (fromIntegral count) hFlush outp -- match the behavior that all data is "flushed to the os" of native implementations
src/Network/Socket/SendFile/Win32.hsc view
@@ -1,6 +1,6 @@ {-# LANGUAGE ForeignFunctionInterface #-} -- | Win32 system-dependent code for 'TransmitFile'. -module Network.Socket.SendFile.Win32 (sendFile') where +module Network.Socket.SendFile.Win32 (_sendFile) where import Data.Int import Data.Word import Foreign.C.Error (throwErrno) @@ -12,8 +12,8 @@ #include <windows.h> -sendFile' :: Handle -> Handle -> Integer -> IO () -sendFile' outp inp count = do +_sendFile :: Handle -> Handle -> Integer -> IO () +_sendFile outp inp count = do hFlush outp -- flush the buffer before invoking transmitFile withHandle_ "Network.Socket.SendFile.Win32.sendFile'" outp $ \outp' -> do withHandle_ "Network.Socket.SendFile.Win32.sendFile'" inp $ \inp' -> do @@ -36,8 +36,8 @@ transmitFile out_fd in_hdl count = failIf_ (== 0) "Network.Socket.SendFile.Win32.transmitFile" (c_TransmitFile out_fd in_hdl count) -foreign import ccall +foreign import ccall unsafe c_get_osfhandle :: FD -> IO IntPtr -foreign import ccall +foreign import ccall unsafe c_TransmitFile :: FD -> HANDLE -> DWORD -> IO (#type BOOL)