Add listen function

This will listen to a connection, responding to pings with a pong and
passing all other lines received to a callback function.

Also add some helper functions for buffering input.

Signed-off-by: John Else <john.else@citrix.com>