mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-03 23:04:08 +01:00
fix use of map.insert: check for existing key and overwrite value
This commit is contained in:
parent
a3e4e31205
commit
ff70e3fbc2
1 changed files with 10 additions and 1 deletions
|
@ -38,8 +38,17 @@ DevMgr::Remember( DevIDRelay devid, const AddrInfo::AddrUnion* saddr )
|
|||
logf( XW_LOGINFO, "%s(devid=%d)", __func__, devid );
|
||||
time_t now = time( NULL );
|
||||
UDPAddrRec rec( saddr, now );
|
||||
|
||||
MutexLock ml( &m_mapLock );
|
||||
m_devAddrMap.insert( pair<DevIDRelay,UDPAddrRec>( devid, rec ) );
|
||||
|
||||
// C++'s insert doesn't replace, but the result tells whether the key was
|
||||
// already there and provides an iterator via which it can be updated
|
||||
pair<map<DevIDRelay,UDPAddrRec>::iterator, bool> result =
|
||||
m_devAddrMap.insert( pair<DevIDRelay,UDPAddrRec>( devid, rec ) );
|
||||
if ( !result.second ) {
|
||||
result.first->second = rec;
|
||||
}
|
||||
|
||||
logf( XW_LOGINFO, "dev->addr map now contains %d entries", m_devAddrMap.size() );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue