示例#1
0
/*
 * Wait for file or timer events and handle them. This function returns 1 if there are no files or
 * timers to wait for, -1 if some error occurred, or 0 if any number of events was successfully
 * handled.
 */
int disHandleEvents(Dispatcher *dis)
{
    int nfds, r;
    fd_set rfds, wfds;
    struct timeval *tv;

P   dbgPrint(stderr, "Calling disPrepareSelect.\n");

    r = disPrepareSelect(dis, &nfds, &rfds, &wfds, &tv);

P   dbgPrint(stderr, "disPrepareSelect returned:\n\tr:    %d\n\tnfds: %d\n", r, nfds);

    if (r < 0) {
        /* Fake a timeout. */

        disProcessSelect(dis, 0, 0, NULL, NULL);

        return 0;
    }
    else if (nfds > 0) {
P       dumpfds(stderr, "\trfds:", nfds, &rfds);
P       dumpfds(stderr, "\twfds:", nfds, &wfds);
    }

P   {
        if (tv == NULL) {
            fprintf(stderr, "\ttv:   NULL\n");
        }
        else {
            fprintf(stderr, "\ttv:   %ld.%06ld\n", tv->tv_sec, tv->tv_usec);
        }
    }

    if (nfds == 0 && tv == NULL) {
P       dbgPrint(stderr, "No more files, no more timeouts: return 1.\n");
        return 1;
    }

P   dbgPrint(stderr, "Calling select.\n");

    r = select(nfds, &rfds, &wfds, NULL, tv);

P   dbgPrint(stderr, "select returned %d\n", r);

    if (r < 0) {
        return r;
    }
    else if (r > 0) {
P       dumpfds(stderr, "\trfds:", nfds, &rfds);
P       dumpfds(stderr, "\twfds:", nfds, &wfds);
    }

P   dbgPrint(stderr, "Calling disProcessSelect.\n");

    disProcessSelect(dis, r, nfds, &rfds, &wfds);

    return 0;
}
示例#2
0
/*
 * Process the results of a call to select(). <r> is select's return value, <rfds> and <wfds>
 * contain the file descriptors that select has marked as readable or writable and <nfds> is the
 * maximum number of file descriptors that may be set in <rfds> or <wfds>.
 */
void nsProcessSelect(NS *ns, int r, int nfds, fd_set *rfds, fd_set *wfds)
{
    disProcessSelect(&ns->dis, r, nfds, rfds, wfds);
}