On Thu, Aug 18, 2011 at 12:56:09AM +0200, Laurent Bercot wrote: > >> How can I do nonblocking read from fd 0 without > >> affecting other processes which might share it? > > > > Assuming no other process will be reading at the same time, you simply > > call poll first (or select, but select requires the fd # to be < 1024) > > to check that it won't block, then call read. select and poll are > > specified to only mark the fd readable if a read would not block. > > Okay. > Same question with writes, then. If I poll() my fd 1 and poll returns > writability, do I have the guarantee that write() will not block ?
Yes, if the OS is not buggy. > Even if fd 1 points to the network ? (I've heard things about a > kernel buffer for outgoing data; if some other process fills up the > kernel buffer between poll() and write(), then write() will block.) The buffer belongs to the individual socket, and poll returning "writable" means there is free space in that buffer. The only way write can block after select/poll on a correct kernel is if another process/thread performs a write on the socket after you call select/poll but before you call write. > Doing asynchronous loops without O_NONBLOCK does not feel right. Perhaps because the Linux kernel developers do not understand robustness and the need to commit resources properly... Rich _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
