コード例 #1
0
ファイル: pipe.c プロジェクト: Maldus512/frosted
static int pipe_poll(struct fnode *f, uint16_t events, uint16_t *revents)
{
    struct pipe_priv *pp;
    *revents = 0;
    if (f->owner != &mod_pipe)
        return -EINVAL;
    pp = (struct pipe_priv *)f->priv;
    if (!pp) {
        return -EINVAL;
    }

    if (f == pp->fno_w) {
        if(pp->fno_r == 0) {
            *revents |= POLLHUP;
            return 1;
        }
        else if ((events & POLLOUT) && (cirbuf_bytesfree(pp->cb) > 0)) {
            *revents = POLLOUT;
            return 1;
        }
    }

    if ((f == pp->fno_r) && (events & POLLIN) && (cirbuf_bytesinuse(pp->cb) > 0)) {
        *revents |= POLLIN;
        return 1;
    }
    return 0;
}
コード例 #2
0
ファイル: pipe.c プロジェクト: Maldus512/frosted
static int pipe_read(struct fnode *f, void *buf, unsigned int len)
{
    struct pipe_priv *pp;
    int out, len_available;
    uint8_t *ptr = buf;

    if (f->owner != &mod_pipe)
        return -EINVAL;

    pp = (struct pipe_priv *)f->priv;
    if (!pp)
        return -EINVAL;

    if (pp->fno_r != f)
        return -EPERM;

    len_available =  cirbuf_bytesinuse(pp->cb);
    if (len_available <= 0) {
        pp->pid_r = scheduler_get_cur_pid();
        task_suspend();
        return SYS_CALL_AGAIN;
    }

    for(out = 0; out < len; out++) {
        /* read data */
        if (cirbuf_readbyte(pp->cb, ptr) != 0)
            break;
        ptr++;
    }
    pp->pid_r = 0;
    return out;
}
コード例 #3
0
static int klog_poll(struct fnode *fno, uint16_t events, uint16_t *revents)
{
    if (events != POLLIN)
        return 0;
    if (cirbuf_bytesinuse(klog.buf) > 0) {
        *revents = POLLIN;
        return 1;
    }
    return 0;
}