Add various timeout and flush behavior

This solves a few problems:

- Failing to find the start packet in the loop will cause this connection to potentially stay open forever. A timeout is added to prevent that.
- Default timeout of 15s on normal socket operations.
- If you don't read the full buffer (and instead disconnect immediately) the plugin generally doesn't work. This was at least the case in my tests on freenode.