| Safe Haskell | Safe-Infered |
|---|
Network.Socket.Splice
Contents
Description
This library implements most efficient socket to socket data transfer loops for proxy servers on each operating system.
On GNU/Linux, it uses and exposes the zero-copy splice() system call:
http://kerneltrap.org/node/6505.
On all other operating systems, it currently falls back to a portable Haskell
implementation – which allocates a single memory buffer in user address space,
then enters an inner loop that uses hGetBufSome and
hPutBuf. This avoids lots of tiny allocations as would otherwise
be caused by recv and
sendAll from the bytestring package.
Cross-platform API for Socket to Socket Data Transfer Loops
splice is the cross-platform API for continous, uni-directional
data transfer between two network sockets.
splice and its implementation primitives hSplice and fdSplice are
infinite loops that are intended to be used with exception handlers and
forkIO.
- Initiate bi-directional continuous data transfer between two sockets:
void . forkIO . try_ $ splice 1024 (sourceSocket, _) (targetSocket, _) void . forkIO . try_ $ splice 1024 (targetSocket, _) (sourceSocket, _)
Arguments
| :: ChunkSize | chunk size. |
| -> (Socket, Maybe Handle) | source socket and possibly its opened handle. |
| -> (Socket, Maybe Handle) | target socket and possibly its opened handle. |
| -> IO () | infinite loop. |
type ChunkSize = ChunkSizeSource
The numeric type to recommend chunk sizes for moving data between sockets
used by both zero-copy and portable implementations of splice.
Indicates whether splice uses zero-copy system calls or the portable user
space Haskell implementation.
Combinators for Exception Handling
Arguments
| :: IO () | action to run which can throw any exception. |
| -> IO () | new action where exceptions are silenced. |
Similar to try but used when an obvious exception
is expected which can be safely ignored.
Implementation Primitives
Infinite loops used in the cross-platform implementation of splice.