update O_NDELAY to O_NONBLOCK, and fix small bugs