From owner-p4-projects@FreeBSD.ORG Thu Aug 21 19:22:44 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6C79D1065690; Thu, 21 Aug 2008 19:22:44 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 310E9106568B for ; Thu, 21 Aug 2008 19:22:44 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 1D3CE8FC12 for ; Thu, 21 Aug 2008 19:22:44 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7LJMhv2092730 for ; Thu, 21 Aug 2008 19:22:43 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7LJMhlb092728 for perforce@freebsd.org; Thu, 21 Aug 2008 19:22:43 GMT (envelope-from ed@FreeBSD.org) Date: Thu, 21 Aug 2008 19:22:43 GMT Message-Id: <200808211922.m7LJMhlb092728@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ed@FreeBSD.org using -f From: Ed Schouten To: Perforce Change Reviews Cc: Subject: PERFORCE change 148030 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2008 19:22:44 -0000 http://perforce.freebsd.org/chv.cgi?CH=148030 Change 148030 by ed@ed_flippo on 2008/08/21 19:21:49 Make watch(8) work again. There's still one thing missing: snp(4) passes back some flags when things overflow/carrier drops/etc. This has not been implemented yet. Affected files ... .. //depot/projects/mpsafetty/sys/dev/snp/snp.c#8 edit Differences ... ==== //depot/projects/mpsafetty/sys/dev/snp/snp.c#8 (text+ko) ==== @@ -30,9 +30,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -53,14 +55,16 @@ static d_read_t snp_read; static d_write_t snp_write; static d_ioctl_t snp_ioctl; +static d_poll_t snp_poll; static struct cdevsw snp_cdevsw = { - .d_version = D_VERSION, - .d_open = snp_open, - .d_read = snp_read, - .d_write = snp_write, - .d_ioctl = snp_ioctl, - .d_name = "snp", + .d_version = D_VERSION, + .d_open = snp_open, + .d_read = snp_read, + .d_write = snp_write, + .d_ioctl = snp_ioctl, + .d_poll = snp_poll, + .d_name = "snp", }; static th_getc_capture_t snp_getc_capture; @@ -80,6 +84,7 @@ struct tty *snp_tty; /* (r) TTY we're snooping. */ struct ttyoutq snp_outq; /* (t) Output queue. */ struct cv snp_outwait; /* (t) Output wait queue. */ + struct selinfo snp_outpoll; /* (t) Output polling. */ }; static void @@ -253,11 +258,50 @@ else *(dev_t *)data = tty_udev(ss->snp_tty); return (0); + case FIONREAD: + tp = ss->snp_tty; + if (tp != NULL) { + tty_lock(tp); + *(int *)data = ttyoutq_bytesused(&ss->snp_outq); + tty_unlock(tp); + } else { + *(int *)data = 0; + } + return (0); default: return (ENOTTY); } } +static int +snp_poll(struct cdev *dev, int events, struct thread *td) +{ + struct snp_softc *ss; + struct tty *tp; + int revents; + + if (devfs_get_cdevpriv((void **)&ss) != 0) + return (events & + (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM)); + + revents = 0; + + if (events & (POLLIN | POLLRDNORM)) { + tp = ss->snp_tty; + if (tp != NULL) { + tty_lock(tp); + if (ttyoutq_bytesused(&ss->snp_outq) > 0) + revents |= events & (POLLIN | POLLRDNORM); + tty_unlock(tp); + } + } + + if (revents == 0) + selrecord(td, &ss->snp_outpoll); + + return (revents); +} + /* * TTY hook events. */ @@ -286,7 +330,9 @@ struct snp_softc *ss = ttyhook_softc(tp); ttyoutq_write(&ss->snp_outq, buf, len); + cv_broadcast(&ss->snp_outwait); + selwakeup(&ss->snp_outpoll); } static moduledata_t snp_mod = {