Network: Use shorter UDP MTU where data can be split across multiple packets.
This commit is contained in:
@@ -33,6 +33,7 @@ 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 SEND_MTU = 1460; ///< Number of bytes we can pack in a single packet
|
||||
static const uint16 SEND_MTU_SHORT = 1400; ///< Number of bytes we can pack in a single packet (conservative)
|
||||
|
||||
static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use?
|
||||
static const byte NETWORK_GAME_INFO_VERSION = 4; ///< What version of game-info do we use?
|
||||
@@ -59,6 +60,7 @@ static const uint NETWORK_GRF_NAME_LENGTH = 80; ///< Maximum l
|
||||
* This limit is reached when PACKET_UDP_SERVER_RESPONSE reaches the maximum size of SEND_MTU bytes.
|
||||
*/
|
||||
static const uint NETWORK_MAX_GRF_COUNT = 62;
|
||||
static const uint NETWORK_MAX_GRF_COUNT_SHORT = 59;
|
||||
|
||||
static const uint NETWORK_NUM_LANGUAGES = 36; ///< Number of known languages (to the network protocol) + 1 for 'any'.
|
||||
|
||||
|
@@ -84,15 +84,17 @@ NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection(bool error)
|
||||
* @param all send the packet using all sockets that can send it
|
||||
* @param broadcast whether to send a broadcast message
|
||||
*/
|
||||
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast)
|
||||
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast, bool short_mtu)
|
||||
{
|
||||
if (this->sockets.size() == 0) this->Listen();
|
||||
|
||||
if (p->size > SEND_MTU) {
|
||||
const uint MTU = short_mtu ? SEND_MTU_SHORT : SEND_MTU;
|
||||
|
||||
if (p->size > MTU) {
|
||||
p->PrepareToSend();
|
||||
|
||||
uint64 token = this->fragment_token++;
|
||||
const uint PAYLOAD_MTU = SEND_MTU - (1 + 2 + 8 + 1 + 1 + 2);
|
||||
const uint PAYLOAD_MTU = MTU - (1 + 2 + 8 + 1 + 1 + 2);
|
||||
|
||||
const uint8 frag_count = (p->size + PAYLOAD_MTU - 1) / PAYLOAD_MTU;
|
||||
|
||||
@@ -108,7 +110,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
|
||||
frag.Send_binary((const char *) p->buffer + offset, payload_size);
|
||||
current_frag++;
|
||||
offset += payload_size;
|
||||
this->SendPacket(&frag, recv, all, broadcast);
|
||||
this->SendPacket(&frag, recv, all, broadcast, short_mtu);
|
||||
frag.ResetState(PACKET_UDP_EX_MULTI);
|
||||
}
|
||||
assert_msg(current_frag == frag_count, "%u, %u", current_frag, frag_count);
|
||||
|
@@ -258,7 +258,7 @@ public:
|
||||
bool Listen();
|
||||
void Close() override;
|
||||
|
||||
void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false);
|
||||
void SendPacket(Packet *p, NetworkAddress *recv, bool all = false, bool broadcast = false, bool short_mtu = false);
|
||||
void ReceivePackets();
|
||||
|
||||
void SendNetworkGameInfo(Packet *p, const NetworkGameInfo *info);
|
||||
|
Reference in New Issue
Block a user