我有一个 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
或将中断的调用配置为使用 sigaction
和 SA_RESTART
再次调用。
- 再次调用
run_reactor_event_loop
是否安全? - ACE_Reactor::restart 方法有什么作用?看起来应该重新启动循环?会有帮助吗?
- 打开
SA_RESTART
有多安全?例如,这是否意味着 ^C 不会停止我的申请? - 还有其他方法可以处理这种情况吗?
最佳答案
检查 Reactor 的构造方式。 ACE_Reactor::open() cal,采用“restart”参数(默认值 = false),告诉它在中断后自动重启 handle_events 方法。
关于c++ - ACE Reactor 在系统调用中断时退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4773265/