On Thursday 22 August 2002 10:49 am, Lars Gullik Bj�nnes wrote:
> Angus Leeming <[EMAIL PROTECTED]> writes:
> | The lyxserver uses the low-level C-functions open(), close(), read() and
> | write() to get, put data to the in,output pipes.
> |
> | Why? Is their a reason why we don't use C++ filestreams?
>
> because you cannot bind it portably to a socket...

Ok, so there's no reason why my server/client test case wouldn't work with 
filestreams as a first step towards Pipestream, SocketStream. Good.

> and you need to register the socket with the xforms socket handler...

You mean 
          
        fl_add_io_callback(pipe, FL_READ, ioCB, 0);
        fl_remove_io_callback(pipe, FL_READ, ioCB);

? Couldn't we achieve the same goal by using a timer to interogate the 
filestream every sec or so.

Note that the magic comment in xforms async_io.c appears to be:

Actual input/output handling is triggered in the main loop via fl_watch_io.

I append the fl_watch_io. Can we not do the same thing with a filestream?

Angus

/*
 * Watch for activities using select or poll. Timeout in milli-second
 */

void
fl_watch_io(FL_IO_REC * io_rec, long msec)
{
    fd_set rfds, wfds, efds;
    struct timeval timeout;
    FL_IO_REC *p;
    int nf;

    if (!io_rec)
    {
        fl_msleep(msec);
        return;
    }

    timeout.tv_usec = 1000 * (msec % 1000);
    timeout.tv_sec = msec / 1000;

    /* initialize the sets */
    rfds = st_rfds;
    wfds = st_wfds;
    efds = st_efds;


    /* now watch it. HP defines rfds to be ints. Althought compiler will
       bark, it is harmless. */
    if ((nf = select(fl_context->num_io, &rfds, &wfds, &efds, &timeout)) < 0)
    {
        /* something is wrong. */
        if (errno == EINTR)
        {
            M_warn("WatchIO", "select interrupted by signal");
        }
        /* select() on some platforms returns -1 with errno==0 */
        else if (errno != 0)
        {
            M_err("select", fl_get_syserror_msg());
        }
    }

    /* time expired */
    if (nf <= 0)
        return;

    /* handle it */
    for (p = io_rec; p; p = p->next)
    {
        if (!p->callback || p->source < 0)
            continue;

        if ((p->mask & FL_READ) && FD_ISSET(p->source, &rfds))
            p->callback(p->source, p->data);

        if ((p->mask & FL_WRITE) && FD_ISSET(p->source, &wfds))
            p->callback(p->source, p->data);

        if ((p->mask & FL_EXCEPT) && FD_ISSET(p->source, &efds))
            p->callback(p->source, p->data);
    }
}

Reply via email to