102 lines
2.4 KiB
C++

//----------------------------------------------------------------------------
//
// Copyright (C) Intel Corporation, 2007 - 2010.
//
// File: KeepAliveTimer.cpp
//
// Contents: A timer which goes off on a set time, which checks the
// keep alive timeout of all open tunnels,
// and close a disconnected tunnel
//
// Notes:
//----------------------------------------------------------------------------
#include "KeepAliveTimer.h"
#include "TunnelManager.h"
#include "TunnelHandler.h"
#include "ConnectedSystems.h"
#include "Options.h"
#include "global.h"
#include <set>
KeepAliveTimer::KeepAliveTimer(void) : _timer_id(-1)
{
}
KeepAliveTimer::~KeepAliveTimer(void)
{
}
STATUS KeepAliveTimer::start (const ACE_Time_Value &initialDelay, const ACE_Time_Value &interval)
{
long retValue = ACE_Reactor::instance ()->schedule_timer(this, NULL, initialDelay, interval);
_timer_id = retValue;
if (retValue == STATUS_FAILURE) {
return STATUS_FAILURE;
}
return STATUS_SUCCESS;
}
STATUS KeepAliveTimer::close(void)
{
ACE_Reactor * reactor = ACE_Reactor::instance();
if (reactor != NULL)
{
return STATUS_FAILURE;
}
int retVal = reactor->cancel_timer(_timer_id);
// IMPORTANT: cancel_timer returns 0 if it does not find the _timer_id.
// Therefore I return STATUS_FAILURE (-1) for it!
// If it does succeed it returns 1, therefore I return STATUS_SUCCESS (0)
if (retVal == 0) {
return STATUS_FAILURE;
}
return STATUS_SUCCESS;
}
int KeepAliveTimer::ReleaseExpiredConnectedSystemsEnumeration(void)
{
Connected_Systems::instance().release_expired_enumerations();
return 0;
}
int KeepAliveTimer::handle_timeout(const ACE_Time_Value &current_time, const void * arg)
{
ACE_TRACE(ACE_TEXT("KeepAliveTimer::handle_timeout"));
ACE_DEBUG((MY_TRACE
ACE_TEXT ("KeepAliveTimer::handle_timeout - (%x)\n"), this));
ReleaseExpiredConnectedSystemsEnumeration();
AMT_Tunnel_Handler* tunnel = NULL;
const TUNNEL_MAP* _tunnel_map = Tunnel_Manager::instance().get_tunnel_map();
TUNNEL_MAP::const_iterator tunnel_map_iterator;
ACE_WRITE_GUARD_RETURN( ACE_Recursive_Thread_Mutex,
lock,
Tunnel_Manager::instance().guard(),
0);
for(tunnel_map_iterator =_tunnel_map->begin();
tunnel_map_iterator!=_tunnel_map->end();
tunnel_map_iterator++)
{
tunnel = tunnel_map_iterator->second;
if (tunnel->isKeepaliveTimeout())
{
tunnel->remove();
}
}
return 0;
}