move timeout interval into config file; cleanup

This commit is contained in:
Eric House 2013-08-12 07:41:48 -07:00
parent a96c0c548f
commit fde50cce32
5 changed files with 25 additions and 15 deletions

View file

@ -20,12 +20,10 @@
#include <unistd.h>
#include "udpack.h"
#include "mlock.h"
#include "configs.h"
UDPAckTrack* UDPAckTrack::s_self = NULL;
#define ACK_LIMIT 60
/* static*/ bool
UDPAckTrack::shouldAck( XWRelayReg cmd )
{
@ -67,6 +65,15 @@ UDPAckTrack::get()
UDPAckTrack::UDPAckTrack()
{
m_nextID = PACKETID_NONE;
int ackLimit;
if ( RelayConfigs::GetConfigs()->
GetValueFor( "UDP_ACK_LIMIT", &ackLimit ) ) {
m_ackLimit = ackLimit;
} else {
assert( 0 );
m_ackLimit = 60;
}
pthread_mutex_init( &m_mutex, NULL );
pthread_t thread;
@ -141,7 +148,7 @@ UDPAckTrack::threadProc()
map<uint32_t, AckRecord>::iterator iter;
for ( iter = m_pendings.begin(); m_pendings.end() != iter; ) {
time_t took = now - iter->second.m_createTime;
if ( ACK_LIMIT < took ) {
if ( m_ackLimit < took ) {
older.push_back( iter->first );
callProc( iter->first, false, &(iter->second) );
m_pendings.erase( iter++ );
@ -161,7 +168,7 @@ UDPAckTrack::threadProc()
string_printf( leaked, ", " );
}
logf( XW_LOGERROR, "%s: these packets leaked (were not ack'd within %d seconds): %s", __func__,
ACK_LIMIT, leaked.c_str() );
m_ackLimit, leaked.c_str() );
}
}
return NULL;

View file

@ -56,6 +56,7 @@ class UDPAckTrack {
uint32_t m_nextID;
pthread_mutex_t m_mutex;
map<uint32_t, AckRecord> m_pendings;
time_t m_ackLimit;
};
#endif

View file

@ -38,12 +38,12 @@ UDPAger::Get()
UDPAger::UDPAger()
{
if ( !RelayConfigs::GetConfigs()-> GetValueFor( "UDP_RECYLE_INTERVAL",
&m_maxInterval ) ) {
&m_maxIntervalSecs ) ) {
assert(0);
}
logf( XW_LOGINFO, "read %d from configs for UDP_RECYLE_INTERVAL",
m_maxInterval );
m_maxInterval *= 1000; // make it milliseconds
m_maxIntervalSecs );
m_maxIntervalMillis = m_maxIntervalSecs * 1000;
pthread_mutex_init( &m_addrTimeMapLock, NULL );
}
@ -72,7 +72,7 @@ UDPAger::Refresh( const AddrInfo* addr )
AgePair* ap = iter->second;
assert( ap->lastSeen() <= readWhen );
int interval = readWhen - ap->lastSeen();
if ( m_maxInterval >= interval ) {
if ( m_maxIntervalMillis >= interval ) {
logf( XW_LOGINFO, "%s: refreshing '%s'; last seen %d "
"milliseconds ago", __func__, b64, interval );
ap->update( readWhen );

View file

@ -32,7 +32,7 @@ class UDPAger {
UDPAger();
void Refresh( const AddrInfo* addr );
bool IsCurrent( const AddrInfo* addr );
uint16_t MaxIntervalSeconds() const { return m_maxInterval / 1000; }
uint16_t MaxIntervalSeconds() const { return m_maxIntervalSecs; }
private:
@ -50,14 +50,13 @@ class UDPAger {
uint32_t m_lastSeen;
};
int m_maxIntervalSecs; /* config: how long since we heard */
int m_maxIntervalMillis;
/* Map socket addresses against times, moving the time forward only
when it's been too long since we saw it. */
int m_maxInterval; /* config: how long since we heard */
map<AddrInfo::AddrUnion, AgePair*> m_addrTimeMap;
pthread_mutex_t m_addrTimeMapLock;
};
#endif

View file

@ -28,8 +28,11 @@ DEVICE_PORTS=10998
# Port for per-device UDP interface (experimental)
UDP_PORT=10997
# How long after we've read from an address before we assume it's recycled
# How long after we've read from an address before we assume it's
# recycled. Also sent to clients as a suggested ping interval
UDP_RECYLE_INTERVAL=60
# consider a packet non-received after how many seconds
UDP_ACK_LIMIT=60
# default 5
SOCK_TIMEOUT_SECONDS=5