Loop in the libevent handlers for read/write

kqueue may be edge triggered, so write/read as much as we can.