Let protocol handler close connection.
Added macros to set READ/WRITE errors before executing the callback.