remove redundant member variable

This commit is contained in:
Eric House 2013-08-13 08:19:32 -07:00
parent c9406c36ae
commit 5be8779749
2 changed files with 15 additions and 21 deletions

View file

@ -321,8 +321,7 @@ CookieRef::HostForSocket( const AddrInfo* addr )
for ( unsigned int ii = 0; ii < VSIZE(m_sockets); ++ii ) { for ( unsigned int ii = 0; ii < VSIZE(m_sockets); ++ii ) {
HostRec* hr = m_sockets[ii]; HostRec* hr = m_sockets[ii];
if ( !!hr && hr->m_addr.equals( *addr ) ) { if ( !!hr && hr->m_addr.equals( *addr ) ) {
assert( hr->m_hostID == ii + 1 ); hid = ii + 1;
hid = hr->m_hostID;
assert( HOST_ID_NONE != hid ); assert( HOST_ID_NONE != hid );
break; break;
} }
@ -340,7 +339,6 @@ CookieRef::SocketForHost( HostID dest )
RWReadLock rrl( &m_socketsRWLock ); RWReadLock rrl( &m_socketsRWLock );
HostRec* hr = m_sockets[dest - 1]; HostRec* hr = m_sockets[dest - 1];
if ( !!hr ) { if ( !!hr ) {
assert( hr->m_hostID == dest );
result = &hr->m_addr; result = &hr->m_addr;
} }
@ -363,7 +361,7 @@ CookieRef::AlreadyHere( unsigned short seed, const AddrInfo* addr,
if ( !addr->equals(hr->m_addr) ) { /* not just a dupe packet */ if ( !addr->equals(hr->m_addr) ) { /* not just a dupe packet */
logf( XW_LOGINFO, "%s: seeds match; socket assumed closed", logf( XW_LOGINFO, "%s: seeds match; socket assumed closed",
__func__ ); __func__ );
*prevHostID = hr->m_hostID; *prevHostID = ii + 1;
} }
break; break;
} }
@ -384,7 +382,6 @@ CookieRef::AlreadyHere( HostID hid, unsigned short seed, const AddrInfo* addr,
RWWriteLock rwl( &m_socketsRWLock ); RWWriteLock rwl( &m_socketsRWLock );
HostRec* hr = m_sockets[hid-1]; HostRec* hr = m_sockets[hid-1];
if ( !!hr ) { if ( !!hr ) {
assert( hr->m_hostID == hid );
if ( seed != hr->m_seed ) { if ( seed != hr->m_seed ) {
*spotTaken = true; *spotTaken = true;
} else if ( addr->equals( hr->m_addr ) ) { } else if ( addr->equals( hr->m_addr ) ) {
@ -426,12 +423,13 @@ CookieRef::removeSocket( const AddrInfo* addr )
HostRec* hr = m_sockets[ii]; HostRec* hr = m_sockets[ii];
if ( !!hr && hr->m_addr.equals( *addr ) ) { if ( !!hr && hr->m_addr.equals( *addr ) ) {
if ( hr->m_ackPending ) { if ( hr->m_ackPending ) {
HostID hid = ii + 1;
logf( XW_LOGINFO, logf( XW_LOGINFO,
"%s: Never got ack; removing hid %d from DB", "%s: Never got ack; removing hid %d from DB",
__func__, hr->m_hostID ); __func__, hid );
DBMgr::Get()->RmDeviceByHid( ConnName(), hr->m_hostID ); DBMgr::Get()->RmDeviceByHid( ConnName(), hid );
m_nPlayersHere -= hr->m_nPlayersH; m_nPlayersHere -= hr->m_nPlayersH;
cancelAckTimer( hr->m_hostID ); cancelAckTimer( hid );
} }
m_sockets[ii] = NULL; m_sockets[ii] = NULL;
delete hr; delete hr;
@ -1001,7 +999,6 @@ CookieRef::updateAck( HostID hostID, bool keep )
RWWriteLock rwl( &m_socketsRWLock ); RWWriteLock rwl( &m_socketsRWLock );
HostRec* hr = m_sockets[hostID-1]; HostRec* hr = m_sockets[hostID-1];
if ( !!hr && hr->m_ackPending ) { if ( !!hr && hr->m_ackPending ) {
assert( hr->m_hostID == hostID );
if ( keep ) { if ( keep ) {
hr->m_ackPending = false; hr->m_ackPending = false;
DBMgr::Get()->NoteAckd( ConnName(), hostID ); DBMgr::Get()->NoteAckd( ConnName(), hostID );
@ -1274,7 +1271,7 @@ CookieRef::notifyOthers( const AddrInfo* addr, XWRelayMsg msg, XWREASON why )
if ( !!hr ) { if ( !!hr ) {
const AddrInfo* other = &hr->m_addr; const AddrInfo* other = &hr->m_addr;
if ( !other->equals( *addr ) ) { if ( !other->equals( *addr ) ) {
send_msg( other, hr->m_hostID, msg, why, false ); send_msg( other, ii + 1, msg, why, false );
} }
} }
} }
@ -1340,7 +1337,6 @@ CookieRef::sendAllHere( bool initial )
RWReadLock rrl( &m_socketsRWLock ); RWReadLock rrl( &m_socketsRWLock );
HostRec* hr = m_sockets[dest-1]; HostRec* hr = m_sockets[dest-1];
if ( !!hr ) { if ( !!hr ) {
assert( hr->m_hostID == dest );
sent = send_with_length( &hr->m_addr, dest, buf, sent = send_with_length( &hr->m_addr, dest, buf,
bufp-buf, true ); bufp-buf, true );
} }
@ -1419,7 +1415,6 @@ CookieRef::noteHeartbeat( const CRefEvent* evt )
RWWriteLock rwl( &m_socketsRWLock ); RWWriteLock rwl( &m_socketsRWLock );
HostRec* hr = m_sockets[id-1]; HostRec* hr = m_sockets[id-1];
if ( !!hr ) { if ( !!hr ) {
assert( hr->m_hostID == id );
if ( hr->m_addr.equals(addr) ) { if ( hr->m_addr.equals(addr) ) {
logf( XW_LOGVERBOSE1, "upping m_lastHeartbeat from %d to %d", logf( XW_LOGVERBOSE1, "upping m_lastHeartbeat from %d to %d",
hr->m_lastHeartbeat, uptime() ); hr->m_lastHeartbeat, uptime() );
@ -1490,11 +1485,11 @@ CookieRef::printSeeds( const char* caller )
for ( unsigned int ii = 0; ii < VSIZE(m_sockets); ++ii ) { for ( unsigned int ii = 0; ii < VSIZE(m_sockets); ++ii ) {
HostRec* hr = m_sockets[ii]; HostRec* hr = m_sockets[ii];
if ( !!hr ) { if ( !!hr ) {
HostID hostID = hr->m_hostID; HostID hostID = ii + 1;
assert( 0 == (bits & (1 << hostID)) ); assert( 0 == (bits & (1 << hostID)) );
bits |= 1 << hostID; bits |= 1 << hostID;
len += snprintf( &buf[len], sizeof(buf)-len, "[%d]%.4x(%d)/%d/%c ", len += snprintf( &buf[len], sizeof(buf)-len, "[%d]%.4x(%d)/%d/%c ",
hr->m_hostID, hr->m_seed, hostID, hr->m_seed,
hr->m_seed, hr->m_addr.socket(), hr->m_seed, hr->m_addr.socket(),
hr->m_ackPending?'a':'A' ); hr->m_ackPending?'a':'A' );
} }
@ -1557,7 +1552,7 @@ CookieRef::_PrintCookieInfo( string& out )
HostRec* hr = m_sockets[ii]; HostRec* hr = m_sockets[ii];
if ( !!hr ) { if ( !!hr ) {
snprintf( buf, sizeof(buf), " HostID=%d; socket=%d;last hbeat=%ld\n", snprintf( buf, sizeof(buf), " HostID=%d; socket=%d;last hbeat=%ld\n",
hr->m_hostID, hr->m_addr.socket(), ii + 1, hr->m_addr.socket(),
hr->m_lastHeartbeat ); hr->m_lastHeartbeat );
out += buf; out += buf;
} }
@ -1575,7 +1570,7 @@ CookieRef::_FormatHostInfo( string* hostIds, string* seeds, string* addrs )
if ( !!hr ) { if ( !!hr ) {
if ( !!hostIds ) { if ( !!hostIds ) {
char buf[8]; char buf[8];
snprintf( buf, sizeof(buf), "%d ", hr->m_hostID ); snprintf( buf, sizeof(buf), "%d ", ii + 1 );
*hostIds += buf; *hostIds += buf;
} }

View file

@ -44,17 +44,16 @@ class CookieMapIterator; /* forward */
struct HostRec { struct HostRec {
public: public:
HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed, bool ackPending ) HostRec(HostID hostID, const AddrInfo* addr, int nPlayersH, int seed,
: m_hostID(hostID) bool ackPending )
, m_addr(*addr) : m_addr(*addr)
, m_nPlayersH(nPlayersH) , m_nPlayersH(nPlayersH)
, m_seed(seed) , m_seed(seed)
, m_lastHeartbeat(uptime()) , m_lastHeartbeat(uptime())
, m_ackPending(ackPending) , m_ackPending(ackPending)
{ {
logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, m_hostID); logf( XW_LOGINFO, "%s created HostRec with id %d", __func__, hostID);
} }
HostID m_hostID;
AddrInfo m_addr; AddrInfo m_addr;
int m_nPlayersH; int m_nPlayersH;
int m_seed; int m_seed;