Skip to content

Commit

Permalink
PortMappingManager: Additional sanity checks
Browse files Browse the repository at this point in the history
  • Loading branch information
past-due committed Aug 10, 2024
1 parent 5c9959e commit e798c8f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/netplay/port_mapping_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bool PortMappingManager::PortMappingAsyncRequest::timed_out(TimePoint t) const
void PortMappingManager::PortMappingAsyncRequest::set_port_mapping_in_progress(TimePoint deadline_, MappingId mappingId_, const std::shared_ptr<PortMappingImpl>& impl_)
{
ASSERT(s == PortMappingDiscoveryStatus::NOT_STARTED || s == PortMappingDiscoveryStatus::IN_PROGRESS, "Invalid state");
ASSERT(impl_ != nullptr, "Missing impl?");
deadline = deadline_;
s = PortMappingDiscoveryStatus::IN_PROGRESS;
mappingId = mappingId_;
Expand All @@ -99,6 +100,7 @@ bool PortMappingManager::PortMappingAsyncRequest::destroy_mapping()
// Destroy the internal mapping.
if (mappingId != WZ_PORT_MAPPING_ID_INVALID)
{
ASSERT_OR_RETURN(false, impl != nullptr, "Missing impl?");
const auto result = impl->destroy_port_mapping(mappingId);
mappingId = WZ_PORT_MAPPING_ID_INVALID;
s = PortMappingDiscoveryStatus::NOT_STARTED;
Expand Down Expand Up @@ -145,7 +147,7 @@ bool PortMappingManager::switchToNextWorkingImpl(PortMappingImpl::Type startingT
{
currImplTypeIdx_ = startingTypeIdx;
currentImpl_ = newImpl;
loadedImpls.push_back(newImpl);
loadedImpls_.push_back(newImpl);
return true;
}
startingTypeIdx = nextImplType(startingTypeIdx);
Expand Down Expand Up @@ -173,12 +175,15 @@ void PortMappingManager::shutdown()
return;
}

currentImpl_->shutdown();
for (auto impl : loadedImpls)
if (currentImpl_)
{
currentImpl_->shutdown();
}
for (auto impl : loadedImpls_)
{
impl->shutdown();
}
loadedImpls.clear();
loadedImpls_.clear();
currentImpl_ = nullptr;

{
Expand Down
2 changes: 1 addition & 1 deletion lib/netplay/port_mapping_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class PortMappingManager
std::unordered_map<PortWithProtocol, PortMappingAsyncRequestPtr> successfulRequests_;

bool isInit_ = false;
std::vector<std::shared_ptr<PortMappingImpl>> loadedImpls;
std::vector<std::shared_ptr<PortMappingImpl>> loadedImpls_;
std::shared_ptr<PortMappingImpl> currentImpl_ = nullptr;
PortMappingImpl::Type currImplTypeIdx_ = PortMappingImpl::Type::Libplum;

Expand Down

0 comments on commit e798c8f

Please sign in to comment.