NetConnection *NetConnection::lookup(const NetAddress *addr) { U32 hashIndex = HashNetAddress(addr); for(NetConnection *walk = mHashTable[hashIndex]; walk; walk = walk->mNextTableHash) if(Net::compareAddresses(addr, walk->getNetAddress())) return walk; return NULL; }
void NetInterface::removeConnection(NetConnection *conn) { for(S32 i = 0; i < mConnectionList.size(); i++) { if(mConnectionList[i] == conn) { mConnectionList.erase_fast(i); break; } } U32 index = conn->getNetAddress().hash() % mConnectionHashTable.size(); U32 startIndex = index; while(mConnectionHashTable[index] != conn) { index++; if(index >= (U32) mConnectionHashTable.size()) index = 0; TNLAssert(index != startIndex, "Attempting to remove a connection that is not in the table.") // not in the table if(index == startIndex) return; } mConnectionHashTable[index] = NULL; // rehash all subsequent entries until we find a NULL entry: for(;;) { index++; if(index >= (U32) mConnectionHashTable.size()) index = 0; if(!mConnectionHashTable[index]) break; NetConnection *rehashConn = mConnectionHashTable[index]; mConnectionHashTable[index] = NULL; U32 realIndex = rehashConn->getNetAddress().hash() % mConnectionHashTable.size(); while(mConnectionHashTable[realIndex] != NULL) { realIndex++; if(realIndex >= (U32) mConnectionHashTable.size()) realIndex = 0; } mConnectionHashTable[realIndex] = rehashConn; } conn->decRef(); }