/* * Handle readable and writable file descriptors in <rfds> and <wfds>, with <nfds> set to the * maximum number of file descriptors that may be set in <rfds> or <wfds>. */ void disHandleFiles(Dispatcher *dis, int nfds, fd_set *rfds, fd_set *wfds) { int fd; for (fd = 0; fd < nfds; fd++) { if (disOwnsFd(dis, fd) && FD_ISSET(fd, rfds)) disHandleReadable(dis, fd); if (disOwnsFd(dis, fd) && FD_ISSET(fd, wfds)) disHandleWritable(dis, fd); } }
int main(int argc, char *argv[]) { int i; Dispatcher *dis = disCreate(); pipe(fd); disOnData(dis, fd[0], handle_fd0, NULL); disOnTime(dis, nowd() + 0.1, handle_timeout, NULL); for (i = 0; i < fd[0]; i++) { make_sure_that(!disOwnsFd(dis, i)); } make_sure_that(disOwnsFd(dis, fd[0])); disRun(dis); return errors; }
/* * Return TRUE if <fd> has been given to <ns> using nsOnData(), FALSE otherwise. */ int nsOwnsFd(NS *ns, int fd) { return disOwnsFd(&ns->dis, fd); }