epoll_wait返回Bad文件描述符

时间:2017-01-30 07:44:07

标签: c++ c linux network-programming epoll

我正在用C ++编写一个多线程服务器。主事件循环如下所示:

for (;loop_enabled_;)
{
    int ret = epoll_wait(epollfd, events, epoll_event_buf_size(), -1);
    if (ret >= 0)
        handle_events(events, events + ret);
    else
    {
        std::error_code ec(errno, std::system_category());
        logger->critical("Error in epoll_wait: {}", ec.message());
        throw std::system_error(ec);
    }
}

但是,在极少数情况下epoll_wait可能会失败Bad file descriptor,即使它已成功完成多次迭代。

根据man epoll_wait

  

错误

EBADF  epfd is not a valid file descriptor.

EFAULT The memory area pointed to by events is not accessible with write permissions.

EINTR  The call was interrupted by a signal handler before either (1) any of the requested events occurred or (2) the timeout expired; see signal(7).

EINVAL epfd is not an epoll file descriptor, or maxevents is less than or equal to zero.

EBADF建议epollfd在我的代码中无效,但由于它已完成多次迭代,invalid在这里意味着什么?在close之前epoll_ctl(EPOLL_CTL_DEL)会导致此吗?

0 个答案:

没有答案