Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Aug 2008 19:22:43 GMT
From:      Ed Schouten <ed@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 148030 for review
Message-ID:  <200808211922.m7LJMhlb092728@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/param.h>
 #include <sys/conf.h>
 #include <sys/fcntl.h>
+#include <sys/filio.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
 #include <sys/module.h>
+#include <sys/poll.h>
 #include <sys/snoop.h>
 #include <sys/sx.h>
 #include <sys/systm.h>
@@ -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 = {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808211922.m7LJMhlb092728>