c++ - ACE Reactor 在系统调用中断时退出

标签 c++ linux network-programming ace reactor

我有一个 ACE react 器,它接受套接字连接并监听这些连接上的传入数据。 react 器在专用线程中运行。这是线程的入口函数:

int TcpServer::svc()
{
    LogDebug("The TCP server on %i is running", mLocalAddr.get_port_number());

    // The current thread will own the reactor. By default, a reactor is owned by
    // the creating thread. A reactor cannot run from not owning thread.
    if (mReactor.owner(ACE_Thread::self()) != 0)
    {
        LogThrow("Could not change the owner of the reactor");
    }

    if (mReactor.run_reactor_event_loop() != 0)
    {
        LogWarning("Reactor loop has quit with an error.");
    }

    return 0;
}

偶尔 run_reactor_event_loop 以 -1 退出并且 errno 报告原因是“系统调用中断”。我该如何处理这种情况?据我所知,我有两个选择:再次调用 run_reactor_event_loop 或将中断的调用配置为使用 sigactionSA_RESTART 再次调用。

  1. 再次调用 run_reactor_event_loop 是否安全?
  2. ACE_Reactor::restart 方法有什么作用?看起来应该重新启动循环?会有帮助吗?
  3. 打开 SA_RESTART 有多安全?例如,这是否意味着 ^C 不会停止我的申请?
  4. 还有其他方法可以处理这种情况吗?

最佳答案

检查 Reactor 的构造方式。 ACE_Reactor::open() cal,采用“restart”参数(默认值 = false),告诉它在中断后自动重启 handle_events 方法。

关于c++ - ACE Reactor 在系统调用中断时退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773265/

相关文章:

c++ - Kinect:从色彩空间到世界坐标

c - 无法构建 zpipe.c(Zlib 示例程序)

linux - 使用 rdtsc 计算秒数

c - 在字符串中遇到空格后程序未写入文件

c - getaddrinfo() 中的段错误

c++ - 计算 5 的 3 次方,但返回 0。为什么?

c++ - SDL 2 无法打开 Controller ,但可以识别操纵杆

c++ - cudaMemcpyFromSymbol和cudaMemcpyToSymbol始终返回cudaErrorInvalidSymbol(13)错误

python - python 套接字可以处理的最大数据包大小是多少?

network-programming - 使用inetd 还是不使用inetd...我什么时候应该将inetd 用于我的网络服务器程序?