2014-01-19 13 views
2

我正在用Android ndk,使用epoll编写网络通信程序。 我发现“epoll_wait”唤醒不是很准确如何处理这种情况:andorid epoll_wait返回-1和errno = 4使用ndk

while(1){ 
    struct epoll_event events[3]; 
    log_string("epoll_wait start");//here will print start time 
    events_len = epoll_wait(_epoll_fd, events, 3, 20 * 1000);// wait 20 second,for test,I use pipe instead of socket,monitor a pipe EPOLLIN event 
    if (events_len <= 0) { 
     log_string("epoll_wait end events_len=%d,errno=%d", events_len, errno);//Normally,the events_len always is 0,and errno is 0 
    } 
} 

上面的代码的PC(如Ubuntun PC)上运行是很正常的,如所预期的方法。

如果它运行在Android手机上(使用Android服务,单独运行的线程)如预期一样。

经过一段时间,epoll_wait变得不是很准确,有时得到-1,errno = 4,有时候等待很久。

所以我只知道现象,但不知道为什么。

你能告诉我为什么,告诉我使用android epoll的最佳做法吗? thx

回答

1

4是EINTR,这意味着你的应用程序得到了一个信号。这不是一个真正的错误,只需重新启动epoll即可。

关于“等待很久”,您的应用程序是否至少保留了部分唤醒锁?

相关问题