corsis/splice — pull request #1 by thoughtpolice (2012-09-02 05:14:06+00:00)
Title: Refactoring of basically everything

This pull request effectively rewrites everything from the README to the file layout to the API.

The prior API was really terrible because it required callers to correctly juggle `Socket`s or `Handle`s depending on whether or not we were using `splice(2)`. That's not good and leaves a lot of room for error and it results in needless code duplication. That was the motivation but I ended up rewriting a lot of code.

* This new API has a unified interface for just splicing `Socket`s together, although it could certainly do the same for `Handle`s. Right now I only focused on sockets.
* The portable loop and the `splice(2)` loop have been separated into different files for maintainability.
* The portable loop was rewritten to just use Sockets and `Network.Socket.ByteString` to pipe data and avoid `malloc` and all the other fancy stuff.
* `bytestring` is now a package dependency as a result, but this isn't really a big deal.
* The `splice(2)` loop was completely rewritten to use non-blocking I/O. Using blocking I/O for file descriptors is terrible in GHC because it completely strangles the event manager, and will end up having bad impacts on other lightweight threads, since the blocking will cause the runtime capability to starve other threads. Using non-blocking I/O should make the event manager/lightweight thread scheduler much happier, with both `-threaded` and without.
* The `splice(2)` call also uses `SPLICE_F_NONBLOCK` accordingly.
* The `splice(2)` loop does seem a bit faster than it originally was, but not quite as fast as the portable version (GHC is really good :)
* The top-level module is just a very simple, very thin wrapper around these APIs. It basically just defaults to one of them and there are no other changes.
* The documentation has been updated to reflect all this.
* Finally, it adds an example of a simply proxy to demonstrate how to use the code.

**THIS SHOULD HAVE THE MAJOR VERSION BUMPED BEFORE RELEASE** since obviously it's a huge API change.