Fixed issue with EAGAIN on sockets.

Previously, when receiving data from sockets, the operation would issue
EAGAIN, causing the connection to fail even though the connection was
still open. This was because no buffered data was available.

This fix uses `select()` to avoid triggering that error when no data can
be read.