Avoid busy loop when receiving incoming stream data.

Checking whether bytes are available is a non-blocking operation,
causing the receive loop to become a busy loop.