Rooster: An epoll Server written in Chicken Scheme and C

My last few blog posts have been sort of leading up to this point: writing an actual server in Chicken Scheme that uses epoll. The server is written in such a way that lets the programmer determine what to do with incoming requests. All the server does is manage sockets and pass input to a programmer-defined request handler. Here's a simple echo server example that uses Rooster:

(require 'rooster)

(define (handler fd rbuf)
  (send-to-client fd rbuf))

(run-rooster handler)

The function `send-to-client` is defined in server.scm and exported so it can be used in an external program. send-to-client writes the buffer to the file descriptor. Note that send-to-client doesn't actually _send_ a buffer to fd. It fills the write buffer for that fd and sends the write buffer when epoll tells the server it's ready to write on that socket.

Rooster requires epoll and Linux for now, but I'd like to fall back to standard poll if epoll isn't available. The main idea I had for Rooster was to create some kind of MUD with it and treat Rooster itself as a sort of game engine.

It'd be interesting to see a new web server come from this as well. I don't see why Rooster couldn't provide the core of any kind of server. New servers could be written on top of Rooster and be completely different from each other.

I'm expecting to be making a ton of changes to Rooster and its API, so it's not at a point where you can rely on the APIs provided unless you feel like locking down to one build of Rooster. I put the code for Rooster on Github earlier today so please take a look. The README should get you started building it and writing your own socket handlers.