diff --git a/src/network/core/tcp.cpp b/src/network/core/tcp.cpp index ad7196c6be..95945aa732 100644 --- a/src/network/core/tcp.cpp +++ b/src/network/core/tcp.cpp @@ -114,6 +114,14 @@ void NetworkTCPSocketHandler::SendPrependPacket(std::unique_ptr packet, this->packet_queue.push_front(std::move(packet)); } +/** + * Shrink the packet send queue to fit (e.g. after having sent the map to a network client) + */ +void NetworkTCPSocketHandler::ShrinkToFitSendQueue() +{ + this->packet_queue.shrink_to_fit(); +} + /** * Sends all the buffered packets out for this client. It stops when: * 1) all packets are send (queue is empty) diff --git a/src/network/core/tcp.h b/src/network/core/tcp.h index d5551ce89e..42dea85ea6 100644 --- a/src/network/core/tcp.h +++ b/src/network/core/tcp.h @@ -14,10 +14,10 @@ #include "address.h" #include "packet.h" +#include "../../core/ring_buffer.hpp" #include #include -#include #include #include #include @@ -37,7 +37,7 @@ enum SendPacketsState { /** Base socket handler for all TCP sockets */ class NetworkTCPSocketHandler : public NetworkSocketHandler { private: - std::deque> packet_queue; ///< Packets that are awaiting delivery + ring_buffer> packet_queue; ///< Packets that are awaiting delivery std::unique_ptr packet_recv; ///< Partially received packet void EmptyPacketQueue(); @@ -56,6 +56,7 @@ public: void SendPacket(std::unique_ptr packet); void SendPrependPacket(std::unique_ptr packet, int queue_after_packet_type); + void ShrinkToFitSendQueue(); void SendPacket(Packet *packet) { diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 62689498e4..8e1fd4d130 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1179,7 +1179,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MAP_OK(Packet * this->SendConfigUpdate(); /* quickly update the syncing client with company details */ - return this->SendCompanyUpdate(); + NetworkRecvStatus status = this->SendCompanyUpdate(); + + this->ShrinkToFitSendQueue(); + + return status; } /* Wrong status for this packet, give a warning to client, and close connection */