Use ring buffer for network TCP packet send queue

pull/590/head
Jonathan G Rennison 10 months ago
parent cf655f624b
commit 175f6c979c

@ -114,6 +114,14 @@ void NetworkTCPSocketHandler::SendPrependPacket(std::unique_ptr<Packet> 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)

@ -14,10 +14,10 @@
#include "address.h"
#include "packet.h"
#include "../../core/ring_buffer.hpp"
#include <atomic>
#include <chrono>
#include <deque>
#include <map>
#include <memory>
#include <vector>
@ -37,7 +37,7 @@ enum SendPacketsState {
/** Base socket handler for all TCP sockets */
class NetworkTCPSocketHandler : public NetworkSocketHandler {
private:
std::deque<std::unique_ptr<Packet>> packet_queue; ///< Packets that are awaiting delivery
ring_buffer<std::unique_ptr<Packet>> packet_queue; ///< Packets that are awaiting delivery
std::unique_ptr<Packet> packet_recv; ///< Partially received packet
void EmptyPacketQueue();
@ -56,6 +56,7 @@ public:
void SendPacket(std::unique_ptr<Packet> packet);
void SendPrependPacket(std::unique_ptr<Packet> packet, int queue_after_packet_type);
void ShrinkToFitSendQueue();
void SendPacket(Packet *packet)
{

@ -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 */

Loading…
Cancel
Save