From owner-freebsd-multimedia Fri Dec 26 11:57:30 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id LAA00669 for multimedia-outgoing; Fri, 26 Dec 1997 11:57:30 -0800 (PST) (envelope-from owner-freebsd-multimedia) Received: from rah.star-gate.com (rah.star-gate.com [204.188.121.18]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id LAA00663 for ; Fri, 26 Dec 1997 11:57:25 -0800 (PST) (envelope-from hasty@rah.star-gate.com) Received: from rah.star-gate.com (localhost.star-gate.com [127.0.0.1]) by rah.star-gate.com (8.8.8/8.8.8) with ESMTP id LAA01833; Fri, 26 Dec 1997 11:57:19 -0800 (PST) (envelope-from hasty@rah.star-gate.com) Message-Id: <199712261957.LAA01833@rah.star-gate.com> X-Mailer: exmh version 2.0gamma 1/27/96 To: multimedia@freebsd.org cc: Randall Hopper Subject: async i/o code example for -current Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 26 Dec 1997 11:57:19 -0800 From: Amancio Hasty Sender: owner-freebsd-multimedia@freebsd.org X-Loop: FreeBSD.org Precedence: bulk I asked Dyson to repost his aio example and he didn't so I dig up his old posting. This is useful for applications such as fxtv when is recording to disk. Cheers, Amancio ------- Forwarded Message Return-Path: owner-freebsd-current@FreeBSD.ORG Received: from sarip.sol.net (sarip.sol.net [169.207.30.120]) by rah.star-gate.com (8.8.8/8.8.8) with ESMTP id MAA00296 for ; Mon, 1 Dec 1997 12:12:38 -0800 (PST) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from hub.freebsd.org (hub.FreeBSD.ORG [204.216.27.18]) by sarip.sol.net (8.8.8/8.8.8/SNNS-1.02) with ESMTP id OAA28385; Mon, 1 Dec 1997 14:11:53 -0600 (CST) Received: from localhost (daemon@localhost) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id LAA06230; Mon, 1 Dec 1997 11:33:22 -0800 (PST) (envelope-from owner-freebsd-current) Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id LAA06160 for current-outgoing; Mon, 1 Dec 1997 11:32:49 -0800 (PST) (envelope-from owner-freebsd-current) Received: from dyson.iquest.net (dyson.iquest.net [198.70.144.127]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id LAA06082 for ; Mon, 1 Dec 1997 11:32:05 -0800 (PST) (envelope-from toor@dyson.iquest.net) Received: (from root@localhost) by dyson.iquest.net (8.8.7/8.8.8) id OAA00376 for current@freebsd.org; Mon, 1 Dec 1997 14:26:34 -0500 (EST) (envelope-from toor) From: "John S. Dyson" Message-Id: <199712011926.OAA00376@dyson.iquest.net> Subject: FYI: usage of new AIO calls To: current@FreeBSD.ORG Date: Mon, 1 Dec 1997 14:26:34 -0500 (EST) X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk For fun (and actually as a result of a comment by Justin Gibbs), I have put together a small program that could maybe be used for streaming tape drives using the new AIO code. Note that if you try this, it must be used only on current kernels on/after 19:00 GMT, Dec 1. This code is NOT pretty, but does show example usage. The code will likely have problems on SMP kernels (unless you are writing to a VCHR device.) - -- John dyson@freebsd.org jdyson@nc.com #include #include #include #include #include #include #include #include #define NBUFS 16 #define BUFSZ (1024*64) struct aiocb *olist[NBUFS]; void *bufaddrs[NBUFS]; int activeflags[NBUFS]; int nactive; int eof; int main( int argc, char *argv[]) { int i; int fd1, fd2; off_t curptr; int nread; int rtval; int errval; if (argc != 2) { fprintf(stderr, "usage: fcp destfile"); exit(0); } fd1 = 0; fd2 = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666); if (fd2 == -1) { perror(argv[1]); exit(1); } for(i=0;i 0)) { if ((eof && (nactive > 0)) || (nactive == NBUFS)) { for (i = 0; i < NBUFS; i++ ) { if (activeflags[i]) { errval = aio_suspend(&olist[i], 1, NULL); if (errval) { perror("aio_suspend"); exit(1); } break; } } } if (nactive > 0) { for (i = 0; i < NBUFS; i++) { if (activeflags[i] == 0) continue; errval = aio_error(olist[i]); if (errval) { if (errval == EINPROGRESS) continue; perror("aio_error1"); exit(1); } activeflags[i] = 0; --nactive; rtval = aio_return(olist[i]); if (rtval != olist[i]->aio_nbytes) { perror("buffer not fully written"); exit(1); } } } for (i = 0; ((eof == 0) && (nactive < NBUFS) && (i < NBUFS)); i++) { if (activeflags[i] == 0) { nread = read( fd1, bufaddrs[i], BUFSZ); if (nread == 0) { eof = 1; break; } if (nread == -1) { perror("read"); exit(1); } olist[i]->aio_offset = curptr; curptr += nread; olist[i]->aio_nbytes = nread; olist[i]->aio_fildes = fd2; olist[i]->aio_buf = bufaddrs[i]; errval = aio_write(olist[i]); activeflags[i] = 1; nactive++; if (errval) { perror("aio_write"); exit(1); } } } } } ------- End of Forwarded Message