-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
622bedf
commit 42b3161
Showing
3 changed files
with
47 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{-# LANGUAGE ForeignFunctionInterface #-} | ||
|
||
module Dumblog.ZeroCopy.Sendfile where | ||
|
||
import Data.Int | ||
import Data.Word | ||
import System.Posix.Types (Fd(Fd)) | ||
import Foreign | ||
import Foreign.C.Types | ||
import Network.Socket (Socket, withFdSocket) | ||
|
||
------------------------------------------------------------------------ | ||
|
||
foreign import ccall unsafe "sys/sendfile.h sendfile64" | ||
c_sendfile :: Fd -> Fd -> Ptr Int64 -> Word64 -> IO Int64 | ||
|
||
sendfile :: Socket -> Fd -> Int64 -> Word64 -> IO Int64 | ||
sendfile outSock inFd offset len = | ||
alloca $ \offsetPtr -> do | ||
poke offsetPtr offset | ||
withFdSocket outSock $ \outFd -> | ||
c_sendfile (fromIntegral outFd) inFd offsetPtr len |