Implement the poll backend for the pipe file type.

This commit is contained in:
Peter Wemm 1997-09-14 02:43:25 +00:00
parent 659ffb486a
commit d080b0b0be
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=29356

View File

@ -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) {
if (events & (POLLIN | POLLRDNORM))
if ((rpipe->pipe_state & PIPE_DIRECTW) ||
(rpipe->pipe_buffer.cnt > 0) ||
(rpipe->pipe_state & PIPE_EOF))
revents |= events & (POLLIN | POLLRDNORM);
case FREAD:
if ( (rpipe->pipe_state & PIPE_DIRECTW) ||
(rpipe->pipe_buffer.cnt > 0) ||
(rpipe->pipe_state & PIPE_EOF)) {
return (1);
}
selrecord(p, &rpipe->pipe_sel);
rpipe->pipe_state |= PIPE_SEL;
break;
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);
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;
if ((rpipe->pipe_state & PIPE_EOF) ||
(wpipe == NULL) ||
(wpipe->pipe_state & PIPE_EOF))
revents |= POLLHUP;
case 0:
if ((rpipe->pipe_state & PIPE_EOF) ||
(wpipe == NULL) ||
(wpipe->pipe_state & PIPE_EOF)) {
return (1);
if (revents == 0) {
if (events & (POLLIN | POLLRDNORM)) {
selrecord(p, &rpipe->pipe_sel);
rpipe->pipe_state |= PIPE_SEL;
}
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