mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 23:50:25 +00:00
Codechange: don't check things outside the lock, that could change while waiting on the lock
This commit is contained in:
parent
ec4104ec6c
commit
3c488e1eb8
@ -138,13 +138,13 @@ struct PacketWriter : SaveFilter {
|
||||
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
/* We want to abort the saving when the socket is closed. */
|
||||
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
|
||||
|
||||
if (this->current == nullptr) this->current = std::make_unique<Packet>(PACKET_SERVER_MAP_DATA, TCP_MTU);
|
||||
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
byte *bufe = buf + size;
|
||||
while (buf != bufe) {
|
||||
size_t written = this->current->Send_bytes(buf, bufe);
|
||||
@ -161,11 +161,11 @@ struct PacketWriter : SaveFilter {
|
||||
|
||||
void Finish() override
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
/* We want to abort the saving when the socket is closed. */
|
||||
if (this->cs == nullptr) SlError(STR_NETWORK_ERROR_LOSTCONNECTION);
|
||||
|
||||
std::lock_guard<std::mutex> lock(this->mutex);
|
||||
|
||||
/* Make sure the last packet is flushed. */
|
||||
if (this->current != nullptr) this->packets.push_back(std::move(this->current));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user