Add logging and fix socket_select blocking

Both changes have been tested.