清单 5. 主循环
while (i < 1000) {
FD_ZERO(&rfds);
FD_SET(fd0, &rfds);
FD_SET(fd1, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 250000;
retval = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
if (retval > 0) {
if (FD_ISSET(fd0, &rfds)) {
n = read(fd0, buf, BUFSIZE - 1);
buf[n] = 0;
printf("FIFO 1: %s\n",buf);
}if (FD_ISSET(fd1, &rfds)) {
n = read(fd1, buf, BUFSIZE - 1);
buf[n] = 0;
printf("FIFO 2: %s\n",buf);
}if (!(swap % 20)) {
msg.task = hello_thread?0:1;
msg.command = HELLO;
write(ctl, &msg, sizeof(msg));
msg.task = hello_thread?1:0;
msg.command = WORLD;
write(ctl, &msg, sizeof(msg));
hello_thread = hello_thread?0:1;
}swap++;
i++;
}
}
© . All rights reserved.