baalexander/node-xmlrpc — pull request #56 by timoxley (2012-08-19 11:14:41+00:00)
Title: Add listening/close events, and a close() function

Irritating using xmlrpc in a test suite as there's no way to stop the server from listening on a port. This patch forwards the http server's 'listening' and 'close' events, and exposes a close() function on the server.
This would allow your server tests to not require use of unreliable stuff like `setTimeout(doStuff, 500)` to "ensure" server is listening.

One tricky issue that needs to be resolved though, is the fact that normal rpc calls are named events, and this could create confusion for anyone who happens to want to call functions named 'close' or 'listening'.

Three solutions:
1. Namespace/private the event names (e.g. "xmlrpc/close" or "_close") to make them far less likely to create conflicts:

2. Expose the http server and listen for events directly on it, e.g
```js
var server = xmlrpc.createServer(options)
server.httpServer.on('listening', onListening)
```

3. Change api to something like:

```js
var server = xmlrpc.createServer().listen(options, onListening)
server.close(onClose)
```
Last solution probably the best but also most disruptive, second solution good middle ground but verbose, first solution easiest, but doesn't fully solve the problem. Let me know which option sounds good to you and it will be done.