我有一个ACE反应器,它接受套接字连接并侦听这些连接上的传入数据。反应器在专用线程中运行。这是线程的输入功能:
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
是否安全?SA_RESTART
的安全性如何?例如,这是否意味着^ C不会停止我的申请?答案 0 :(得分:1)
检查Reactor的构造方式。 ACE_Reactor :: open()cal,取“restart”参数(默认值= false),告诉它在中断后自动重启handle_events方法。