splice-0.3.1: Socket to Socket Data Splicing (supports all operating systems)

Safe HaskellSafe-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 Linux, it uses and exposes the zero-copy splice() system call: http://kerneltrap.org/node/6505.

On other operating systems, it currently falls back to a portable Haskell implementation – which first allocates a constant-sized memory buffer in user address, then enters an inner loop which uses hGetBufSome and hPutBuf on this user-space buffer. This avoids tony of tiny allocations as might otherwise be caused by recv and sendAll from the bytestring package.

Synopsis

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.

It is an infinite loop that is intended to be used with forkIO:

 void . forkIO . try_ $ splice 1024 sourceSocket targetSocket
 void . forkIO . try_ $ splice 1024 targetSocket sourceSocket

spliceSource

Arguments

:: ChunkSize

chunk size.

-> Socket

source socket.

-> Socket

target socket.

-> IO ()

infinite loop.

Pipes data from one socket to another in an infinite loop.

On Linux this uses the splice() system call and eliminates copying between kernel and user address spaces.

On other operating systems, a portable Haskell implementation utilizes a user space buffer.

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.

zeroCopySource

Arguments

:: Bool

True if splice uses zero-copy system calls; otherwise, false.

Indicates whether splice uses zero-copy system calls or the portable user space Haskell implementation.

Combinators for Exception Handling

try_Source

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.