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:
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
hPutBuf on this user-space buffer. This avoids tony of tiny
allocations as might otherwise be caused by
sendAll from the
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
void . forkIO . try_ $ splice 1024 sourceSocket targetSocket void . forkIO . try_ $ splice 1024 targetSocket sourceSocket
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.
The numeric type to recommend chunk sizes for moving data between sockets
used by both zero-copy and portable implementations of
splice uses zero-copy system calls or the portable user
space Haskell implementation.