我正在尝试将 inotify 与 select() 调用一起使用。
time_out 设置为 3 秒。我似乎无法让它工作。
选择始终返回零。
代码片段,
fd_set fds;
//fd is descriptor for inotify_init
FD_ZERO(&fds);
FD_SET(fd, &fds);
struct timeval time_wait;
while(true)
{
time_wait.tv_sec=3;
time_wait.tv_usec=0;
i = 0;
res = select(fd , &fds, NULL, NULL, &time_wait);
if (ret == -1) {
printf("Error occured in inotify read \n");
break;
}
if(ret == 0) {
//always triggers
printf("timed out \n");
continue;
}
//Never reaches here
printf("Event occured \n");
......
}
如果我不使用 select,它工作得很好。它也可以与 poll() 配合使用。
我还尝试了 inotify_init1() 和 IN_NONBLOCK
有人能告诉我我做错了什么吗?