Skip to content

Commit 93dc769

Browse files
committed
Add CSteamNetworkConnectionP2P::RemoveP2PConnectionMapByRemoteInfo.
(Refactor, no functional change.) P4:6554171
1 parent 48da417 commit 93dc769

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,25 @@ bool CSteamNetworkConnectionP2P::BInitP2PConnectionCommon( SteamNetworkingMicros
292292
return true;
293293
}
294294

295+
void CSteamNetworkConnectionP2P::RemoveP2PConnectionMapByRemoteInfo()
296+
{
297+
AssertLocksHeldByCurrentThread();
298+
299+
if ( m_idxMapP2PConnectionsByRemoteInfo >= 0 )
300+
{
301+
if ( g_mapP2PConnectionsByRemoteInfo.IsValidIndex( m_idxMapP2PConnectionsByRemoteInfo ) && g_mapP2PConnectionsByRemoteInfo[ m_idxMapP2PConnectionsByRemoteInfo ] == this )
302+
{
303+
g_mapP2PConnectionsByRemoteInfo[ m_idxMapP2PConnectionsByRemoteInfo ] = nullptr; // just for grins
304+
g_mapP2PConnectionsByRemoteInfo.RemoveAt( m_idxMapP2PConnectionsByRemoteInfo );
305+
}
306+
else
307+
{
308+
AssertMsg( false, "g_mapIncomingP2PConnections bookkeeping mismatch" );
309+
}
310+
m_idxMapP2PConnectionsByRemoteInfo = -1;
311+
}
312+
}
313+
295314
bool CSteamNetworkConnectionP2P::BEnsureInP2PConnectionMapByRemoteInfo( SteamDatagramErrMsg &errMsg )
296315
{
297316
Assert( !m_identityRemote.IsInvalid() );
@@ -797,19 +816,7 @@ void CSteamNetworkConnectionP2P::FreeResources()
797816
AssertLocksHeldByCurrentThread();
798817

799818
// Remove from global map, if we're in it
800-
if ( m_idxMapP2PConnectionsByRemoteInfo >= 0 )
801-
{
802-
if ( g_mapP2PConnectionsByRemoteInfo.IsValidIndex( m_idxMapP2PConnectionsByRemoteInfo ) && g_mapP2PConnectionsByRemoteInfo[ m_idxMapP2PConnectionsByRemoteInfo ] == this )
803-
{
804-
g_mapP2PConnectionsByRemoteInfo[ m_idxMapP2PConnectionsByRemoteInfo ] = nullptr; // just for grins
805-
g_mapP2PConnectionsByRemoteInfo.RemoveAt( m_idxMapP2PConnectionsByRemoteInfo );
806-
}
807-
else
808-
{
809-
AssertMsg( false, "g_mapIncomingP2PConnections bookkeeping mismatch" );
810-
}
811-
m_idxMapP2PConnectionsByRemoteInfo = -1;
812-
}
819+
RemoveP2PConnectionMapByRemoteInfo();
813820

814821
// Release signaling
815822
if ( m_pSignaling )

src/steamnetworkingsockets/clientlib/steamnetworkingsockets_p2p.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ class CSteamNetworkConnectionP2P : public CSteamNetworkConnectionBase
403403

404404
static CSteamNetworkConnectionP2P *FindDuplicateConnection( CSteamNetworkingSockets *pInterfaceLocal, int nLocalVirtualPort, const SteamNetworkingIdentity &identityRemote, int nRemoteVirtualPort, bool bOnlySymmetricConnections, CSteamNetworkConnectionP2P *pIgnore );
405405

406+
void RemoveP2PConnectionMapByRemoteInfo();
406407
bool BEnsureInP2PConnectionMapByRemoteInfo( SteamDatagramErrMsg &errMsg );
407408

408409
protected:

0 commit comments

Comments
 (0)