snapframework/snap-server — pull request #24 by ndmitchell (2012-05-25 18:48:19+00:00)
Title: Addition of setInitHandler

I am writing something which needs to spawn a web server, wait until it is ready to receive connections, and then tell someone the port. There are two related problems:

* The server does not say when it has started
* If you set the port to be 0, then a free port is allocated - there is no easy way to see which port the server ended up on.

This patch solves both these issues with an initial handler, which is run after the server is started, and gets passed the real sockets, which you can call socketPort on to find which port the server is running on.