LibCore: Put a limit on how many unsent messages an IPC server queues

This patch adds a limit of 200 unsent messages per client. If a client
does not handle its incoming messages and we manage to queue up 200
messages for it, we'll now disconnect that client. :^)
This commit is contained in:
Andreas Kling 2019-11-03 12:40:57 +01:00
parent 31c1b8ec3e
commit 53cfed7c8b
Notes: sideshowbarker 2024-07-19 11:27:15 +09:00

View File

@ -95,6 +95,12 @@ namespace Server {
#endif
if (try_send_message(message, extra_data))
return;
if (m_queue.size() >= max_queued_messages) {
dbg() << "Connection::post_message: Client has too many queued messages already, disconnecting it.";
shutdown();
return;
}
QueuedMessage queued_message { message, extra_data };
if (!extra_data.is_empty())
queued_message.message.extra_size = extra_data.size();
@ -232,6 +238,8 @@ namespace Server {
ServerMessage message;
ByteBuffer extra_data;
};
static const int max_queued_messages = 200;
Queue<QueuedMessage, 16> m_queue;
int m_client_id { -1 };