Date: Sun, 3 Dec 1995 14:58:40 +1100 From: Bruce Evans <bde@zeta.org.au> To: freebsd-hackers@freebsd.org, witr@rwwa.com Subject: Re: Proper way to determine non-blocking status... Message-ID: <199512030358.OAA07217@godzilla.zeta.org.au>
next in thread | raw e-mail | index | archive | help
>Even though it seems like it is almost never done by >existing driver code, would I be correct in assuming that >the *right* way to determine if a device read is allowed to >sleep or not is the following? >int xxread(dev_t dev, struct uio *uio, int ioflag) >{ > if (ioflag & IO_NDELAY) { > /* Can't block here */ > return EWOULDBLOCK; > } else { /* Otherwise try again */ > /* Can sleep here */ > ... > } >} Yes. See tty.c for examples. In open/ioctl/close you have to check O_NONBLOCK (aka FNONBLOCK) instead of IO_NDELAY. The ugl^H^H^Hrightly formatted way is: int xxread(dev, uio, ioflag) dev_t dev; struct uio *uio; int ioflag; { /* Return early for nonblocking reads. */ if (ioflag & IO_NDELAY) return (EWOULDBLOCK); /* Can sleep here. */ ... } Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199512030358.OAA07217>