From 23a59e8097b8929192e21b3d8a2fcc77bfff6128 Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 21 Aug 2013 21:32:55 -0700 Subject: [PATCH] sometimes a device goes away and we don't notice, so when it comes back just reuse its record rather than asserting there's no record there. --- xwords4/relay/cref.cpp | 10 +++++++--- xwords4/relay/cref.h | 25 ++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index c76e537bd..115659ae6 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -972,11 +972,15 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn, HostID* hidp, { RWWriteLock rwl( &m_socketsRWLock ); - HostRec* hr = new HostRec( hostid, addr, nPlayersH, seed, !reconn ); + HostRec* hr = m_sockets[hostid-1]; + if ( NULL == hr ) { + hr = new HostRec( hostid, addr, nPlayersH, seed, !reconn ); + m_sockets[hostid-1] = hr; + } else { + hr->update( addr, nPlayersH, seed, !reconn ); + } logf( XW_LOGINFO, "%s: adding socket rec with ts %lx", __func__, addr->created() ); - assert( NULL == m_sockets[hostid-1] ); - m_sockets[hostid-1] = hr; } printSeeds(__func__); diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index 1bf266b6c..e9e800eb6 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -44,16 +44,23 @@ class CookieMapIterator; /* forward */ struct HostRec { public: -HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed, - bool ackPending ) - : m_addr(*addr) - , m_nPlayersH(nPlayersH) - , m_seed(seed) - , m_lastHeartbeat(uptime()) - , m_ackPending(ackPending) - { - logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, hostID); + HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed, + bool ackPending ) + : m_seed(seed) + { + update( addr, nPlayersH, seed, ackPending ); + logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, hostID); + } + void update( const AddrInfo* addr, int nPlayersH, int seed, bool ackPending ) + { + assert( seed == m_seed ); + m_addr = *addr; + m_nPlayersH = nPlayersH; + m_seed = seed; + m_lastHeartbeat = uptime(); + m_ackPending = ackPending; } + AddrInfo m_addr; int m_nPlayersH; int m_seed;