2011-01-23 96 views
0

我有一個ACE反應器,它接受套接字連接並偵聽這些連接上的傳入數據。反應器在專用線程中運行。這是線程的入口函數:ACE Reactor在系統調用中斷時退出

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. 還有其他方法可以處理這種情況嗎?
+0

你看看源代碼嗎? – 2011-01-23 10:30:34

回答

1

檢查Reactor是如何構建的。 ACE_Reactor :: open()cal,採用「restart」參數(default = false),告訴它在中斷後自動重新啓動handle_events方法。