为什么只捕获了一个消息,应该是一条呀,求解答,我是新手,弄不太明白。

int main(void){
struct pollfd fds[2];
int ret;
int i = 0;
fds[0].fd = STDIN_FILENO;
fds[0].events = POLLIN;
fds[1].fd = STDOUT_FILENO;
fds[1].events = POLLOUT;

while(i<5){
ret = poll(fds,2,TIMEOUT*1000);
if(ret == -1){
perror("poll");
return 1;
}
if(!ret){
printf("%d seconds elapsed. \n",TIMEOUT);
}
if(fds[0].revents & POLLIN){
printf("stdin is readable\n");
}
if(fds[1].revents & POLLOUT){
printf("stdout is writeable\n");
}
i++;
}
return 0;
}
运行./poll 的时候我也没有输出啊,为什么直接就打印了stdout is writable 。是不是stdout就一直被用着呢 。还有当我运行 ./poll < lala.txt 的时候,由于用了stdin ,它打印出了 stdin isreadable ,但是为什么一打就是5条啊。

神不在的星期二
浏览 113回答 1
1回答

互换的青春

fds[1].events = POLLOUT;应该把是 fds[0].events = POLLOUT;
打开App,查看更多内容
随时随地看视频慕课网APP