diff options
author | peter <peter@FreeBSD.org> | 1997-09-14 02:34:14 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-09-14 02:34:14 +0000 |
commit | 0fc35eb0c2c1977021d3467ba247eea56ef25d9c (patch) | |
tree | 6bec0f525a36bab3e11dbe8f6670a52e5a49e6a5 /sys/kern/uipc_socket.c | |
parent | e44c10ddd21c4e1bb2a2bc0d9148120692773bc1 (diff) | |
download | FreeBSD-src-0fc35eb0c2c1977021d3467ba247eea56ef25d9c.zip FreeBSD-src-0fc35eb0c2c1977021d3467ba247eea56ef25d9c.tar.gz |
Extend select backend for sockets to work with a poll interface (more
detail is passed back and forwards). This mostly came from NetBSD, except
that our interfaces have changed a lot and this funciton is in a different
part of the kernel.
Obtained from: NetBSD
Diffstat (limited to 'sys/kern/uipc_socket.c')
-rw-r--r-- | sys/kern/uipc_socket.c | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index cd8830d..79bfaac 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 - * $Id: uipc_socket.c,v 1.29 1997/08/21 20:33:39 bde Exp $ + * $Id: uipc_socket.c,v 1.30 1997/09/02 20:05:57 bde Exp $ */ #include <sys/param.h> @@ -42,6 +42,7 @@ #include <sys/mbuf.h> #include <sys/domain.h> #include <sys/kernel.h> +#include <sys/poll.h> #include <sys/protosw.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -1085,38 +1086,35 @@ sohasoutofband(so) } int -soselect(struct socket *so, int which, struct proc *p) +sopoll(struct socket *so, int events, struct ucred *cred, struct proc *p) { + int revents = 0; int s = splnet(); - switch (which) { - case FREAD: - if (soreadable(so)) { - splx(s); - return (1); - } - selrecord(p, &so->so_rcv.sb_sel); - so->so_rcv.sb_flags |= SB_SEL; - break; + if (events & (POLLIN | POLLRDNORM)) + if (soreadable(so)) + revents |= events & (POLLIN | POLLRDNORM); - case FWRITE: - if (sowriteable(so)) { - splx(s); - return (1); + if (events & (POLLOUT | POLLWRNORM)) + if (sowriteable(so)) + revents |= events & (POLLOUT | POLLWRNORM); + + if (events & (POLLPRI | POLLRDBAND)) + if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) + revents |= events & (POLLPRI | POLLRDBAND); + + if (revents == 0) { + if (events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) { + selrecord(p, &so->so_rcv.sb_sel); + so->so_rcv.sb_flags |= SB_SEL; } - selrecord(p, &so->so_snd.sb_sel); - so->so_snd.sb_flags |= SB_SEL; - break; - case 0: - if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) { - splx(s); - return (1); + if (events & (POLLOUT | POLLWRNORM)) { + selrecord(p, &so->so_snd.sb_sel); + so->so_snd.sb_flags |= SB_SEL; } - selrecord(p, &so->so_rcv.sb_sel); - so->so_rcv.sb_flags |= SB_SEL; - break; } + splx(s); - return (0); + return (revents); } |