【问题标题】:how to deal with this case: andorid epoll_wait return -1 and errno=4 used ndk这种情况如何处理:andorid epoll_wait return -1 and errno=4 used ndk
【发布时间】:2014-01-19 04:53:56
【问题描述】:

我正在用 Android ndk 编写网络通信程序,使用 epoll。 我发现'epoll_wait'方法唤醒不是很准确

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 Service,单独线程运行),一开始就符合预期。

一段时间后,epoll_wait变得不是很准确,有时得到-1和errno=4,有时等待很长时间。

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

你能告诉我为什么并告诉我使用 android epoll 的最佳实践吗? 谢谢

【问题讨论】:

    标签: android android-ndk epoll


    【解决方案1】:

    4 是 EINTR,这意味着您的应用收到了信号。这并不是真正的错误,只需重新启动 epoll。

    关于“等待很长时间”,您的应用是否至少持有部分唤醒锁?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多