From owner-freebsd-hackers Sat Dec 2 20:01:53 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id UAA15661 for hackers-outgoing; Sat, 2 Dec 1995 20:01:53 -0800 Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id UAA15645 for ; Sat, 2 Dec 1995 20:01:39 -0800 Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.9/8.6.9) id OAA07217; Sun, 3 Dec 1995 14:58:40 +1100 Date: Sun, 3 Dec 1995 14:58:40 +1100 From: Bruce Evans Message-Id: <199512030358.OAA07217@godzilla.zeta.org.au> To: freebsd-hackers@freebsd.org, witr@rwwa.com Subject: Re: Proper way to determine non-blocking status... Sender: owner-hackers@freebsd.org Precedence: bulk >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