Make PipeIOStream.write_to_fd handle EAGAIN/EWOULDBLOCK and EBADF properly.