Handle socket errors better
Previously, when reading from or writing to a socket failed, we would
handle errors by simply producing an error message and exiting the
program. While that works, it does not allow for the postrun command,
specified in the configuration file, to run.
Fix this by adding a return value to readit/writeit-like functions, and
handling nonzero return values in the socket_read()/socket_write()
function, which then call a cleanup function that does the same exit
(but which will allow for doing the necessary postrun stuff).
Fixes #47 on Github