From owner-freebsd-questions@FreeBSD.ORG Thu May 27 15:05:16 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3CCEA16A4D1 for ; Thu, 27 May 2004 15:05:16 -0700 (PDT) Received: from gizmo09ps.bigpond.com (gizmo09ps.bigpond.com [144.140.71.19]) by mx1.FreeBSD.org (Postfix) with SMTP id C812D43D31 for ; Thu, 27 May 2004 15:05:14 -0700 (PDT) (envelope-from andrew@areilly.bpc-users.org) Received: (qmail 25025 invoked from network); 27 May 2004 21:54:48 -0000 Received: from unknown (HELO psmam03.bigpond.com) (144.135.25.75) by gizmo09ps.bigpond.com with SMTP; 27 May 2004 21:54:48 -0000 Received: from cpe-138-130-184-234.nsw.bigpond.net.au ([138.130.184.234]) by psmam03.bigpond.com(MAM REL_3_4_2a 89/5149566) with SMTP id 5149566; Fri, 28 May 2004 08:04:31 +1000 Received: (qmail 8931 invoked by uid 1000); 27 May 2004 22:05:00 -0000 Date: Fri, 28 May 2004 08:05:00 +1000 From: Andrew Reilly To: freebsd-questions@freebsd.org Message-ID: <20040527220500.GA8220@gurney.reilly.home> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Subject: Programming question: fcntl(...,O_ASYNC) on device? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2004 22:05:16 -0000 Hi, oh gurus, I'm venturing into a realm of Unix programming that I had previously been able to avoid: asynchronous event processing, with or without threads. Can anyone suggest why the following test-case program always produces: $ ./test-case test-case: can't set O_ASYNC on device: Invalid argument ? For reference to details, my system is 4-STABLE about a week old, and the device in question is a Midiman1010 sound card with the 4Front (OSS) driver. (FreeBSD's native pcm device doesn't support this card.) What I'm trying to achieve is the Unix equivalent of a DSP-style IO interrupt for audio processing. I want the main body of the code to be able to go on and do UI things without sitting and waiting at the inevitable read(....,fd), but I also want processing of the input data to proceed immediately that data is available, irrespective of what the UI code is doing (so just O_NONBLOCK isn't what I'm after). The code doesn't work if the O_ASYNC argument to fcntl is O_NONBLOCK|O_ASYNC either. Any clues? Thanks for any suggestions. ----snip----- /* standard OSS includes */ #include #include #include #include #include #include #define BUF_SIZE 4096 int fd; unsigned char buf[BUF_SIZE]; void got_data(int sig) { /* foo: do something with buf[] */ if (-1 == read(fd, buf, BUF_SIZE)) /* initiate next read */ err(1, "can't read from device"); } int main(int argc, char **argv) { signal(SIGIO, got_data); fd=open("/dev/dsp6", O_RDONLY); if (-1 == fd) err(1, "can't open device"); if (-1 == fcntl(fd, F_SETFL, O_ASYNC)) err(1, "can't set O_ASYNC on device"); if (-1 == read(fd, buf, BUF_SIZE)) /* initiate next read */ err(1, "can't read from device"); for (;;) { /* UI */ } return 0; } ----un-snip------ -- Andrew