Fix IOStream flow control under kqueue.

An early attempt to detect closed connections in kqueue led
us to always read from the socket when data was available,
defeating any higher-level flow control.

Add a test to verify this behavior.
Also fix flow control for the select IOLoop.