Merge pull request #12304 from sepalani/pcap-io

BBA/HLE: Fix random PCAP file corruption
This commit is contained in:
Admiral H. Curtiss 2023-11-23 19:26:00 +01:00 committed by GitHub
commit feeac104d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View File

@ -49,6 +49,7 @@ void PCAP::AddHeader(u32 link_type)
m_fp->WriteBytes(&hdr, sizeof(hdr));
}
// Not thread-safe, concurrency between multiple calls to IOFile::WriteBytes.
void PCAP::AddPacket(const u8* bytes, size_t size)
{
std::chrono::system_clock::time_point now(std::chrono::system_clock::now());

View File

@ -123,6 +123,9 @@ void PCAPSSLCaptureLogger::LogBBA(const void* data, std::size_t length)
{
if (!Config::Get(Config::MAIN_NETWORK_DUMP_BBA))
return;
// Concurrency between CEXIETHERNET's RecvHandlePacket and SendFromDirectFIFO
const std::lock_guard lock(m_io_mutex);
m_file->AddPacket(static_cast<const u8*>(data), length);
}

View File

@ -7,6 +7,7 @@
#include <cstddef>
#include <map>
#include <memory>
#include <mutex>
#ifdef _WIN32
#include <WinSock2.h>
@ -111,6 +112,7 @@ private:
const sockaddr_in& to);
std::unique_ptr<Common::PCAP> m_file;
std::mutex m_io_mutex;
std::map<s32, u32> m_read_sequence_number;
std::map<s32, u32> m_write_sequence_number;
};