diff options
author | Rubidium <rubidium@openttd.org> | 2021-04-18 14:56:25 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-04-25 21:27:54 +0200 |
commit | 21f58ab437992761caefd11f931c45086cc3d216 (patch) | |
tree | c0cecc4d612b75f6d71a0212a47856faff3d9f57 | |
parent | d6000c2ec5f61c599d8859b981f2dac6a92e0755 (diff) | |
download | openttd-21f58ab437992761caefd11f931c45086cc3d216.tar.xz |
Change: use 32 KiB packets to transfer the savegame
-rw-r--r-- | src/network/core/config.h | 16 | ||||
-rw-r--r-- | src/network/network_server.cpp | 4 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/network/core/config.h b/src/network/core/config.h index 572b4720d..866d1791d 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -31,7 +31,21 @@ static const uint16 NETWORK_ADMIN_PORT = 3977; ///< The defau static const uint16 NETWORK_DEFAULT_DEBUGLOG_PORT = 3982; ///< The default port debug-log is sent to (TCP) static const uint16 UDP_MTU = 1460; ///< Number of bytes we can pack in a single UDP packet -static const uint16 TCP_MTU = 1460; ///< Number of bytes we can pack in a single TCP packet +/* + * Technically a TCP packet could become 64kiB, however the high bit is kept so it becomes possible in the future + * to go to (significantly) larger packets if needed. This would entail a strategy such as employed for UTF-8. + * + * Packets up to 32 KiB have the high bit not set: + * 00000000 00000000 0bbbbbbb aaaaaaaa -> aaaaaaaa 0bbbbbbb + * Send_uint16(GB(size, 0, 15) + * + * Packets up to 1 GiB, first uint16 has high bit set so it knows to read a + * next uint16 for the remaining bits of the size. + * 00dddddd cccccccc bbbbbbbb aaaaaaaa -> cccccccc 10dddddd aaaaaaaa bbbbbbbb + * Send_uint16(GB(size, 16, 14) | 0b10 << 14) + * Send_uint16(GB(size, 0, 16)) + */ +static const uint16 TCP_MTU = 32767; ///< Number of bytes we can pack in a single TCP packet static const uint16 COMPAT_MTU = 1460; ///< Number of bytes we can pack in a single packet for backward compatibility static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use? diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 5489db848..7d10f04fe 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -158,7 +158,7 @@ struct PacketWriter : SaveFilter { /* 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 = new Packet(PACKET_SERVER_MAP_DATA); + if (this->current == nullptr) this->current = new Packet(PACKET_SERVER_MAP_DATA, TCP_MTU); std::lock_guard<std::mutex> lock(this->mutex); @@ -169,7 +169,7 @@ struct PacketWriter : SaveFilter { if (!this->current->CanWriteToPacket(1)) { this->AppendQueue(); - if (buf != bufe) this->current = new Packet(PACKET_SERVER_MAP_DATA); + if (buf != bufe) this->current = new Packet(PACKET_SERVER_MAP_DATA, TCP_MTU); } } |