Use ioctl to set non-blocking mode.

For better cross-platform compatibility.