The tcp package

[ Tags: bsd3, library, network ] [ Propose Tags ]

A purely functional TCP implementation

Peng Li's TCP stack based on the formal HOL4 TCP specification at, code base on the unified events and threads project

[Skip to Readme]


Versions 0.0.2
Dependencies base, containers, old-time [details]
License BSD3
Author Peng Li and Stephan Zdancewic
Maintainer Don Stewart
Category Network
Home page
Uploaded Tue Apr 7 23:06:20 UTC 2009 by DonaldStewart
Distributions NixOS:0.0.2
Downloads 411 total (6 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for tcp-0.0.2

[back to package description]
* Linux 2.6.x
* GHC 6.5
* libaio --- the Linux Asynchonrous I/O Library.
* libipq --- the iptables development library (iptables-dev in Debian)

  If you wish to try the web server, make sure that the HTML files are
  on one of these file systems: ext2, ext3, jfs, xfs.  Otherwise, AIO
  may not work.

Files and directories:
IOLib/      : Low-level asynchronous I/O library
    Chunk.hs     : A type-safe representation of memory buffers
    AIO.hs       : FFI wrappers for the Linux AIO library
    Epoll.hs     : FFI wrappers for the Linux epoll interface
    NBIO.hs      : FFI wrappers for some non-blocking socket primitives
    PacketIO.hs  : FFI wrappers for sending/receiving IP packets.
    TCP.hs       : A proof-of-concept, purely functional TCP stack.

ThreadLib/  : The application-level thread library
    Thread.hs    : CPS Monad and system calls.
    Workers.hs   : Some standard and reusable event loops for constructing 
                   application-level schedulers.
                   A default scheduler implementation is also provided.
    FileIO.hs    : Synchronous disk library, implemented using Linux AIO
    SockIO.hs    : Synchronous socket library, implemented using standard 
                   non-blocking sockets with epoll.
    TCPSockIO.hs : Synchronous socket library, implemented using the
                   user-level, customized TCP stack.
    Mutex.hs     : A simple mutex library.

WebClient/  : An HTTP load generator application

WebServer/  : A web server application.  It can be linked with 
              either SockIO or TCPSockIO.

Compile and run:
First, make sure that libaio is installed on your system and you are
using a development snapshot GHC 6.5.  Then, run the shell script
"" to compile all the sources.  This should create three
executable files:


Run them.  They are self-documented.  To use Server_tcp.bin, you should
first run "make setup" in the WebServer/ directory to setup iptables.
Read the Makefile for more information.

Programming with threads
Just use Server.hs and LoadGen.hs as templates to start.

Programming with events
The scheduler is part of your application.  You can use some standard
event loops predefined in Workers.hs, or you can write your own.

Q: How to use another event source like *poll/*IO/kqueue/whatever?

A: First, wrap up the C function calls using FFI.  AIO.hs and
mod_aio.c is a good demo to start with.  Then, add system calls and
write your own event loops :-)

Q: How to add system calls?

A: The current setup is not quite modular yet---you will have to add a
line in Thread.hs for each system call you would like to add.  In the
future, it is possible to make the Trace interface user-pluggable by
adding an extra level of indirection.

Q: How to write my own event loops?

A: As a demo, LoadGen.hs has a customized event loop.  It does not do
anything fancy, though.

Q: How is the TCP stack?

A: The current implementation is purely functional and it is quite
   slow.  It is roughly 3x-8x slower than the linux kernel TCP stack.
   It only implemented server sockets---active TCP connections are
   not implemented yet.