diff options
author | peter <peter@FreeBSD.org> | 1997-09-14 02:43:25 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1997-09-14 02:43:25 +0000 |
commit | 84169dafe13181317abdf92a749f1de64b953727 (patch) | |
tree | adff83350b4d3e7be91e7e3335dcc1ac97e1823d /sys/kern/sys_pipe.c | |
parent | 222aa7e6ff5915f0344f0369aa9d64dcf1c5c016 (diff) | |
download | FreeBSD-src-84169dafe13181317abdf92a749f1de64b953727.zip FreeBSD-src-84169dafe13181317abdf92a749f1de64b953727.tar.gz |
Implement the poll backend for the pipe file type.
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r-- | sys/kern/sys_pipe.c | 77 |
1 files changed, 38 insertions, 39 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 35394dc..07e7ebc 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -16,7 +16,7 @@ * 4. Modifications may be freely made to this file if the above conditions * are met. * - * $Id: sys_pipe.c,v 1.31 1997/08/05 22:24:17 dyson Exp $ + * $Id: sys_pipe.c,v 1.32 1997/09/02 20:05:53 bde Exp $ */ /* @@ -58,6 +58,7 @@ #include <sys/filio.h> #include <sys/ttycom.h> #include <sys/stat.h> +#include <sys/poll.h> #include <sys/signalvar.h> #include <sys/sysproto.h> #include <sys/pipe.h> @@ -89,11 +90,12 @@ static int pipe_read __P((struct file *fp, struct uio *uio, static int pipe_write __P((struct file *fp, struct uio *uio, struct ucred *cred)); static int pipe_close __P((struct file *fp, struct proc *p)); -static int pipe_select __P((struct file *fp, int which, struct proc *p)); +static int pipe_poll __P((struct file *fp, int events, struct ucred *cred, + struct proc *p)); static int pipe_ioctl __P((struct file *fp, int cmd, caddr_t data, struct proc *p)); static struct fileops pipeops = - { pipe_read, pipe_write, pipe_ioctl, pipe_select, pipe_close }; + { pipe_read, pipe_write, pipe_ioctl, pipe_poll, pipe_close }; /* * Default pipe buffer size(s), this can be kind-of large now because pipe @@ -864,7 +866,7 @@ pipe_write(fp, uio, cred) /* * We have no more space and have something to offer, - * wake up selects. + * wake up select/poll. */ pipeselwakeup(wpipe); @@ -912,7 +914,7 @@ pipe_write(fp, uio, cred) /* * We have something to offer, - * wake up select. + * wake up select/poll. */ if (wpipe->pipe_buffer.cnt) pipeselwakeup(wpipe); @@ -965,50 +967,47 @@ pipe_ioctl(fp, cmd, data, p) } int -pipe_select(fp, which, p) +pipe_poll(fp, events, cred, p) struct file *fp; - int which; + int events; + struct ucred *cred; struct proc *p; { register struct pipe *rpipe = (struct pipe *)fp->f_data; struct pipe *wpipe; + int revents = 0; wpipe = rpipe->pipe_peer; - switch (which) { - - case FREAD: - if ( (rpipe->pipe_state & PIPE_DIRECTW) || - (rpipe->pipe_buffer.cnt > 0) || - (rpipe->pipe_state & PIPE_EOF)) { - return (1); + if (events & (POLLIN | POLLRDNORM)) + if ((rpipe->pipe_state & PIPE_DIRECTW) || + (rpipe->pipe_buffer.cnt > 0) || + (rpipe->pipe_state & PIPE_EOF)) + revents |= events & (POLLIN | POLLRDNORM); + + if (events & (POLLOUT | POLLWRNORM)) + if (wpipe == NULL || (wpipe->pipe_state & PIPE_EOF) || + ((wpipe->pipe_state & PIPE_DIRECTW) == 0) && + (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF) + revents |= events & (POLLOUT | POLLWRNORM); + + if ((rpipe->pipe_state & PIPE_EOF) || + (wpipe == NULL) || + (wpipe->pipe_state & PIPE_EOF)) + revents |= POLLHUP; + + if (revents == 0) { + if (events & (POLLIN | POLLRDNORM)) { + selrecord(p, &rpipe->pipe_sel); + rpipe->pipe_state |= PIPE_SEL; } - selrecord(p, &rpipe->pipe_sel); - rpipe->pipe_state |= PIPE_SEL; - break; - - case FWRITE: - if ((wpipe == NULL) || - (wpipe->pipe_state & PIPE_EOF) || - (((wpipe->pipe_state & PIPE_DIRECTW) == 0) && - (wpipe->pipe_buffer.size - wpipe->pipe_buffer.cnt) >= PIPE_BUF)) { - return (1); - } - selrecord(p, &wpipe->pipe_sel); - wpipe->pipe_state |= PIPE_SEL; - break; - - case 0: - if ((rpipe->pipe_state & PIPE_EOF) || - (wpipe == NULL) || - (wpipe->pipe_state & PIPE_EOF)) { - return (1); + + if (events & (POLLOUT | POLLWRNORM)) { + selrecord(p, &rpipe->pipe_sel); + rpipe->pipe_state |= PIPE_SEL; } - - selrecord(p, &rpipe->pipe_sel); - rpipe->pipe_state |= PIPE_SEL; - break; } - return (0); + + return (revents); } int |