Changeset 180:f7c6a039c519 in finroc_plugins_tcp


Ignore:
Timestamp:
08.12.2019 07:57:02 (3 months ago)
Author:
Max Reichardt <mreichardt@…>
Branch:
17.03
Phase:
public
Message:

Makes watch dog monitor TCP thread

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internal/tPeerImplementation.cpp

    r178 r180  
    3535#include "core/tRuntimeEnvironment.h" 
    3636#include "plugins/network_transport/generic_protocol/tUriConnector.h" 
     37#include "rrlib/watchdog/tWatchDogTask.h" 
    3738 
    3839//---------------------------------------------------------------------- 
     
    300301  tTCPThread(tPeerImplementation& implementation) : 
    301302    tThread("TCP Thread"), 
    302     implementation(implementation) 
    303   { 
     303    implementation(implementation), 
     304    watch_task(new tWatchTask()) 
     305  { 
     306  } 
     307 
     308  void UpdateWatchDogDeadline() 
     309  { 
     310    watch_task->SetDeadLine(rrlib::time::Now() + std::chrono::seconds(4)); 
    304311  } 
    305312 
    306313private: 
     314 
     315  class tWatchTask : public rrlib::watchdog::tWatchDogTask 
     316  { 
     317  public: 
     318    tWatchTask() : 
     319      tWatchDogTask(true) 
     320    {} 
     321 
     322    virtual void HandleWatchdogAlert() override 
     323    { 
     324      FINROC_LOG_PRINT_STATIC(ERROR, "TCP thread got stuck"); 
     325      this->Deactivate(); 
     326    } 
     327  }; 
     328 
    307329  virtual void Run() override 
    308330  { 
     331    UpdateWatchDogDeadline(); 
    309332    try 
    310333    { 
     
    323346      FINROC_LOG_PRINT(ERROR, "TCP thread exited with ", ex); 
    324347    } 
     348    watch_task.reset(); 
    325349  } 
    326350 
     
    331355 
    332356  tPeerImplementation& implementation; 
     357  std::unique_ptr<tWatchTask> watch_task;  // Separate object in order to deregister task before watch dog register is deallocated 
    333358}; 
    334359 
     
    613638{ 
    614639  FINROC_LOG_PRINT(DEBUG_VERBOSE_2, "Alive ", rrlib::time::Now().time_since_epoch().count()); 
     640  static_cast<tTCPThread&>(*thread).UpdateWatchDogDeadline(); 
    615641 
    616642  // connect to other peers 
Note: See TracChangeset for help on using the changeset viewer.