1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 08:52:40 +01:00

Codechange: use span to send bytes to Packet and add span recv function

This commit is contained in:
Rubidium
2024-01-28 13:28:07 +01:00
committed by rubidium42
parent b6c75dec3a
commit 15d02f51ed
3 changed files with 29 additions and 14 deletions

View File

@@ -145,14 +145,13 @@ struct PacketWriter : SaveFilter {
if (this->current == nullptr) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
byte *bufe = buf + size;
while (buf != bufe) {
size_t written = this->current->Send_bytes(buf, bufe);
buf += written;
std::span<const byte> to_write(buf, size);
while (!to_write.empty()) {
to_write = this->current->Send_bytes(to_write);
if (!this->current->CanWriteToPacket(1)) {
this->packets.push_back(std::move(this->current));
if (buf != bufe) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
if (!to_write.empty()) this->current = std::make_unique<Packet>(this->cs, PACKET_SERVER_MAP_DATA, TCP_MTU);
}
}