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.
This commit is contained in:
Eric House 2013-08-21 21:32:55 -07:00
parent 45998fd2c0
commit 23a59e8097
2 changed files with 23 additions and 12 deletions

View file

@ -972,11 +972,15 @@ CookieRef::increasePlayerCounts( CRefEvent* evt, bool reconn, HostID* hidp,
{ {
RWWriteLock rwl( &m_socketsRWLock ); 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__, logf( XW_LOGINFO, "%s: adding socket rec with ts %lx", __func__,
addr->created() ); addr->created() );
assert( NULL == m_sockets[hostid-1] );
m_sockets[hostid-1] = hr;
} }
printSeeds(__func__); printSeeds(__func__);

View file

@ -44,16 +44,23 @@ class CookieMapIterator; /* forward */
struct HostRec { struct HostRec {
public: public:
HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed, HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed,
bool ackPending ) bool ackPending )
: m_addr(*addr) : m_seed(seed)
, m_nPlayersH(nPlayersH)
, m_seed(seed)
, m_lastHeartbeat(uptime())
, m_ackPending(ackPending)
{ {
update( addr, nPlayersH, seed, ackPending );
logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, hostID); 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; AddrInfo m_addr;
int m_nPlayersH; int m_nPlayersH;
int m_seed; int m_seed;