P2P use ScheduledMethodThinker instead of IThinker

This simplifies the class heirarchy a bit.

P4:6159900,6161857
This commit is contained in:
Fletcher Dunn
2020-10-29 12:19:29 -07:00
parent dc1ddd746a
commit 5e94deb7d6
4 changed files with 17 additions and 16 deletions
@@ -1001,7 +1001,7 @@ void CSteamNetworkConnectionP2P::ConnectionStateChanged( ESteamNetworkingConnect
m_usecNextEvaluateTransport = k_nThinkTime_ASAP;
SetNextThinkTimeASAP();
for ( CConnectionTransportP2PBase *pTransportP2P: m_vecAvailableTransports )
pTransportP2P->m_pSelfAsThinker->SetNextThinkTimeASAP();
pTransportP2P->EnsureP2PTransportThink( k_nThinkTime_ASAP );
break;
}
@@ -1827,10 +1827,9 @@ void CSteamNetworkConnectionP2P::PeerSelectedTransportChanged()
//
/////////////////////////////////////////////////////////////////////////////
CConnectionTransportP2PBase::CConnectionTransportP2PBase( const char *pszDebugName, CConnectionTransport *pSelfBase, IThinker *pSelfThinker )
CConnectionTransportP2PBase::CConnectionTransportP2PBase( const char *pszDebugName, CConnectionTransport *pSelfBase )
: m_pszP2PTransportDebugName( pszDebugName )
, m_pSelfAsConnectionTransport( pSelfBase )
, m_pSelfAsThinker( pSelfThinker )
{
m_pingEndToEnd.Reset();
m_usecEndToEndInFlightReplyTimeout = 0;
@@ -1853,7 +1852,7 @@ void CConnectionTransportP2PBase::P2PTransportTrackSentEndToEndPingRequest( Stea
if ( bAllowDelayedReply )
m_usecEndToEndInFlightReplyTimeout += k_usecSteamDatagramRouterPendClientPing; // Is this the appropriate constant to use?
m_pSelfAsThinker->EnsureMinThinkTime( m_usecEndToEndInFlightReplyTimeout );
EnsureP2PTransportThink( m_usecEndToEndInFlightReplyTimeout );
}
}
@@ -1947,7 +1946,7 @@ void CConnectionTransportP2PBase::P2PTransportThink( SteamNetworkingMicroseconds
if ( m_usecEndToEndInFlightReplyTimeout )
usecNextThink = std::min( usecNextThink, m_usecEndToEndInFlightReplyTimeout );
m_pSelfAsThinker->EnsureMinThinkTime( usecNextThink );
EnsureP2PTransportThink( usecNextThink );
}
void CConnectionTransportP2PBase::P2PTransportEndToEndConnectivityNotConfirmed( SteamNetworkingMicroseconds usecNow )
@@ -76,7 +76,6 @@ public:
// Virtual base classes. (We don't directly derive, since we are a mixin,
// but all classes that derive from us will derive from these base classes.)
CConnectionTransport *const m_pSelfAsConnectionTransport;
IThinker *const m_pSelfAsThinker;
const char *const m_pszP2PTransportDebugName;
@@ -132,18 +131,25 @@ public:
m_nReplyTimeoutsSinceLastRecv = 0;
}
void P2PTransportTrackSentEndToEndPingRequest( SteamNetworkingMicroseconds usecNow, bool bAllowDelayedReply );
void P2PTransportThink( SteamNetworkingMicroseconds usecNow );
void P2PTransportEndToEndConnectivityConfirmed( SteamNetworkingMicroseconds usecNow );
void P2PTransportEndToEndConnectivityNotConfirmed( SteamNetworkingMicroseconds usecNow );
// Populate m_routeMetrics. If we're not really available, then the metrics should be set to a huge score
virtual void P2PTransportUpdateRouteMetrics( SteamNetworkingMicroseconds usecNow ) = 0;
inline void EnsureP2PTransportThink( SteamNetworkingMicroseconds usecWhen )
{
m_scheduleP2PTransportThink.EnsureMinScheduleTime( this, &CConnectionTransportP2PBase::P2PTransportThink, usecWhen );
}
protected:
CConnectionTransportP2PBase( const char *pszDebugName, CConnectionTransport *pSelfBase, IThinker *pSelfThinker );
CConnectionTransportP2PBase( const char *pszDebugName, CConnectionTransport *pSelfBase );
// Shortcut to get connection and upcast
CSteamNetworkConnectionP2P &Connection() const;
virtual void P2PTransportThink( SteamNetworkingMicroseconds usecNow );
ScheduledMethodThinker<CConnectionTransportP2PBase> m_scheduleP2PTransportThink;
};
/// A peer-to-peer connection that can use different types of underlying transport
@@ -23,7 +23,7 @@ namespace SteamNetworkingSocketsLib {
CConnectionTransportP2PICE::CConnectionTransportP2PICE( CSteamNetworkConnectionP2P &connection )
: CConnectionTransportUDPBase( connection )
, CConnectionTransportP2PBase( "ICE", this, this )
, CConnectionTransportP2PBase( "ICE", this )
, m_pICESession( nullptr )
{
m_nAllowedCandidateTypes = 0;
@@ -84,7 +84,6 @@ void CConnectionTransportP2PICE::TransportFreeResources()
m_pICESession->Destroy();
m_pICESession = nullptr;
}
ClearNextThinkTime();
find_and_remove_element( Connection().m_vecAvailableTransports, this );
CConnectionTransport::TransportFreeResources();
@@ -235,7 +234,7 @@ void CConnectionTransportP2PICE::RecvRendezvous( const CMsgICERendezvous &msg, S
}
}
void CConnectionTransportP2PICE::Think( SteamNetworkingMicroseconds usecNow )
void CConnectionTransportP2PICE::P2PTransportThink( SteamNetworkingMicroseconds usecNow )
{
// Are we dead?
if ( !m_pICESession || Connection().m_pTransportICEPendingDelete )
@@ -245,7 +244,7 @@ void CConnectionTransportP2PICE::Think( SteamNetworkingMicroseconds usecNow )
return;
}
P2PTransportThink( usecNow );
CConnectionTransportP2PBase::P2PTransportThink( usecNow );
}
void CConnectionTransportP2PICE::P2PTransportUpdateRouteMetrics( SteamNetworkingMicroseconds usecNow )
@@ -25,7 +25,6 @@ struct UDPSendPacketContext_t;
class CConnectionTransportP2PICE final
: public CConnectionTransportUDPBase
, public CConnectionTransportP2PBase
, public IThinker
, private IICESessionDelegate
{
public:
@@ -43,11 +42,9 @@ public:
virtual void TransportFreeResources() override;
virtual bool BCanSendEndToEndData() const override;
// IThinker
virtual void Think( SteamNetworkingMicroseconds usecNow ) override;
// CConnectionTransportP2PBase
virtual void P2PTransportUpdateRouteMetrics( SteamNetworkingMicroseconds usecNow ) override;
virtual void P2PTransportThink( SteamNetworkingMicroseconds usecNow ) override;
/// Fill in SDR-specific fields to signal
void PopulateRendezvousMsg( CMsgSteamNetworkingP2PRendezvous &msg, SteamNetworkingMicroseconds usecNow );