mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-19 20:49:11 +00:00
(svn r21363) -Add: support for limiting the amount of (accepted) incoming data
This commit is contained in:
@@ -39,7 +39,7 @@ public:
|
||||
bool SendPackets(bool closing_down = false);
|
||||
bool IsPacketQueueEmpty();
|
||||
|
||||
Packet *ReceivePacket();
|
||||
virtual Packet *ReceivePacket();
|
||||
|
||||
bool CanSendReceive();
|
||||
|
||||
|
@@ -62,6 +62,7 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
|
||||
{
|
||||
this->status = STATUS_INACTIVE;
|
||||
this->client_id = _network_client_id++;
|
||||
this->receive_limit = _settings_client.network.bytes_per_frame_burst;
|
||||
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
||||
this->SetInfo(ci);
|
||||
ci->client_playas = COMPANY_INACTIVE_CLIENT;
|
||||
@@ -77,6 +78,19 @@ ServerNetworkGameSocketHandler::~ServerNetworkGameSocketHandler()
|
||||
OrderBackup::ResetUser(this->client_id);
|
||||
}
|
||||
|
||||
Packet *ServerNetworkGameSocketHandler::ReceivePacket()
|
||||
{
|
||||
/* Only allow receiving when we have some buffer free; this value
|
||||
* can go negative, but eventually it will become positive again. */
|
||||
if (this->receive_limit <= 0) return NULL;
|
||||
|
||||
/* We can receive a packet, so try that and if needed account for
|
||||
* the amount of received data. */
|
||||
Packet *p = this->NetworkTCPSocketHandler::ReceivePacket();
|
||||
if (p != NULL) this->receive_limit -= p->size;
|
||||
return p;
|
||||
}
|
||||
|
||||
NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvStatus status)
|
||||
{
|
||||
assert(status != NETWORK_RECV_STATUS_OKAY);
|
||||
@@ -1540,6 +1554,11 @@ void NetworkServer_Tick(bool send_frame)
|
||||
/* Now we are done with the frame, inform the clients that they can
|
||||
* do their frame! */
|
||||
FOR_ALL_CLIENT_SOCKETS(cs) {
|
||||
/* We allow a number of bytes per frame, but only to the burst amount
|
||||
* to be available for packet receiving at any particular time. */
|
||||
cs->receive_limit = min(cs->receive_limit + _settings_client.network.bytes_per_frame,
|
||||
_settings_client.network.bytes_per_frame_burst);
|
||||
|
||||
/* Check if the speed of the client is what we can expect from a client */
|
||||
if (cs->status == NetworkClientSocket::STATUS_ACTIVE) {
|
||||
/* 1 lag-point per day */
|
||||
|
@@ -70,10 +70,12 @@ public:
|
||||
uint32 last_token_frame; ///< The last frame we received the right token
|
||||
ClientStatus status; ///< Status of this client
|
||||
CommandQueue outgoing_queue; ///< The command-queue awaiting delivery
|
||||
int receive_limit; ///< Amount of bytes that we can receive at this moment
|
||||
|
||||
ServerNetworkGameSocketHandler(SOCKET s);
|
||||
~ServerNetworkGameSocketHandler();
|
||||
|
||||
virtual Packet *ReceivePacket();
|
||||
NetworkRecvStatus CloseConnection(NetworkRecvStatus status);
|
||||
void GetClientName(char *client_name, size_t size) const;
|
||||
|
||||
|
Reference in New Issue
Block a user