summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-09-23 16:51:15 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-09-23 16:51:15 +0000
commit6bb276a1685d8546283d224a3d249c66cc329264 (patch)
tree5e1c80d6cad38a8a82f5832e1e315103e7029eb9 /sys/net
parent96675671ec2520ade2f83b31563ab4da72bd443d (diff)
Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater poll(2) functionality instead of emulating it via the select backend. Adapted from NetBSD and including some changes from FreeBSD. Tested by many, deraadt@ OK
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/bpf.c44
-rw-r--r--sys/net/if_tun.c33
-rw-r--r--sys/net/ppp_tty.c4
3 files changed, 36 insertions, 45 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index f2e09c84d78..7e42edc8e62 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.37 2003/07/29 23:02:52 itojun Exp $ */
+/* $OpenBSD: bpf.c,v 1.38 2003/09/23 16:51:13 millert Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -48,6 +48,7 @@
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/socket.h>
+#include <sys/poll.h>
#include <sys/kernel.h>
#include <net/if.h>
@@ -83,7 +84,7 @@ int bpf_movein(struct uio *, int, struct mbuf **, struct sockaddr *);
void bpf_attachd(struct bpf_d *, struct bpf_if *);
void bpf_detachd(struct bpf_d *);
int bpf_setif(struct bpf_d *, struct ifreq *);
-int bpfselect(dev_t, int, struct proc *);
+int bpfpoll(dev_t, int, struct proc *);
int bpfkqfilter(dev_t, struct knote *);
static __inline void bpf_wakeup(struct bpf_d *);
void bpf_catchpacket(struct bpf_d *, u_char *, size_t, size_t,
@@ -928,46 +929,37 @@ bpf_ifname(ifp, ifr)
}
/*
- * Support for select() system call
- *
- * Return true iff the specific operation will not block indefinitely.
- * Otherwise, return false but make a note that a selwakeup() must be done.
+ * Support for poll() system call
*/
int
-bpfselect(dev, rw, p)
+bpfpoll(dev, events, p)
register dev_t dev;
- int rw;
+ int events;
struct proc *p;
{
register struct bpf_d *d;
- register int s;
+ register int s, revents;
+
+ revents = events & (POLLIN | POLLRDNORM);
+ if (revents == 0)
+ return (0); /* only support reading */
- if (rw != FREAD)
- return (0);
/*
* An imitation of the FIONREAD ioctl code.
*/
d = &bpf_dtab[minor(dev)];
-
s = splimp();
- if (d->bd_hlen != 0 || (d->bd_immediate && d->bd_slen != 0)) {
+ if (d->bd_hlen == 0 && (!d->bd_immediate || d->bd_slen == 0)) {
+ revents = 0; /* no data waiting */
/*
- * There is data waiting.
+ * if there's a timeout, mark the time we started waiting.
*/
- splx(s);
- return (1);
+ if (d->bd_rtout != -1 && d->bd_rdStart == 0)
+ d->bd_rdStart = ticks;
+ selrecord(p, &d->bd_sel);
}
-
- /*
- * if there isn't data waiting, and there's a timeout,
- * mark the time we started waiting.
- */
- if (d->bd_rtout != -1 && d->bd_rdStart == 0)
- d->bd_rdStart = ticks;
-
- selrecord(p, &d->bd_sel);
splx(s);
- return (0);
+ return (revents);
}
struct filterops bpfread_filtops =
diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c
index 8bfe75e4182..5e8b3fe950a 100644
--- a/sys/net/if_tun.c
+++ b/sys/net/if_tun.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_tun.c,v 1.49 2003/08/15 20:32:19 tedu Exp $ */
+/* $OpenBSD: if_tun.c,v 1.50 2003/09/23 16:51:13 millert Exp $ */
/* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */
/*
@@ -53,6 +53,7 @@
#include <sys/device.h>
#include <sys/vnode.h>
#include <sys/signalvar.h>
+#include <sys/poll.h>
#include <sys/conf.h>
#include <machine/cpu.h>
@@ -128,7 +129,7 @@ int tun_output(struct ifnet *, struct mbuf *, struct sockaddr *,
int tunioctl(dev_t, u_long, caddr_t, int, struct proc *);
int tunread(dev_t, struct uio *, int);
int tunwrite(dev_t, struct uio *, int);
-int tunselect(dev_t, int, struct proc *);
+int tunpoll(dev_t, int, struct proc *);
int tunkqfilter(dev_t, struct knote *);
@@ -742,12 +743,12 @@ tunwrite(dev, uio, ioflag)
* anyway, it either accepts the packet or drops it.
*/
int
-tunselect(dev, rw, p)
+tunpoll(dev, events, p)
dev_t dev;
- int rw;
+ int events;
struct proc *p;
{
- int unit, s;
+ int unit, revents, s;
struct tun_softc *tp;
struct ifnet *ifp;
struct mbuf *m;
@@ -757,27 +758,25 @@ tunselect(dev, rw, p)
tp = &tunctl[unit];
ifp = &tp->tun_if;
+ revents = 0;
s = splimp();
- TUNDEBUG(("%s: tunselect\n", ifp->if_xname));
+ TUNDEBUG(("%s: tunpoll\n", ifp->if_xname));
- switch (rw) {
- case FREAD:
+ if (events & (POLLIN | POLLRDNORM)) {
IFQ_POLL(&ifp->if_snd, m);
if (m != NULL) {
- splx(s);
TUNDEBUG(("%s: tunselect q=%d\n", ifp->if_xname,
ifp->if_snd.ifq_len));
- return 1;
+ revents |= events & (POLLIN | POLLRDNORM);
+ } else {
+ TUNDEBUG(("%s: tunpoll waiting\n", ifp->if_xname));
+ selrecord(p, &tp->tun_rsel);
}
- selrecord(curproc, &tp->tun_rsel);
- break;
- case FWRITE:
- splx(s);
- return 1;
}
+ if (events & (POLLOUT | POLLWRNORM))
+ revents |= events & (POLLOUT | POLLWRNORM);
splx(s);
- TUNDEBUG(("%s: tunselect waiting\n", ifp->if_xname));
- return 0;
+ return (revents);
}
/* Does not currently work */
diff --git a/sys/net/ppp_tty.c b/sys/net/ppp_tty.c
index af96ee6df94..5e6c30d6f44 100644
--- a/sys/net/ppp_tty.c
+++ b/sys/net/ppp_tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ppp_tty.c,v 1.18 2003/09/18 19:32:20 tedu Exp $ */
+/* $OpenBSD: ppp_tty.c,v 1.19 2003/09/23 16:51:13 millert Exp $ */
/* $NetBSD: ppp_tty.c,v 1.12 1997/03/24 21:23:10 christos Exp $ */
/*
@@ -706,7 +706,7 @@ pppasyncctlp(sc)
struct tty *tp;
int s;
- /* Put a placeholder byte in canq for ttselect()/ttnread(). */
+ /* Put a placeholder byte in canq for ttpoll()/ttnread(). */
s = spltty();
tp = (struct tty *) sc->sc_devp;
putc(0, &tp->t_canq);