LibGUI/WindowServer: Rework packet serialization

Instead of sending while serializing (what even was that), we serialize
the whole packet into a buffer which can be sent in one go. First of all
this reduces the number of sends by a lot. This also fixes WindowServer
ending up sending partial packets when client is not responsive.
Previously we would just try sending once, if any send failed the send
was aborted while partial packet was already transmitted. This lead to
packet stream being out of sync leading to the client killing itself.
Now we allow 64 KiB outgoing buffer per client. If this buffer ever fills
up, we will not send partial packets.
This commit is contained in:
2026-04-07 09:13:34 +03:00
parent 2f9b8b6fc9
commit a4ba1da65a
7 changed files with 373 additions and 292 deletions

View File

@@ -16,7 +16,22 @@ Window::~Window()
smo_delete(m_smo_key);
LibGUI::EventPacket::DestroyWindowEvent packet;
(void)packet.send_serialized(m_client_fd);
BAN::Vector<uint8_t> buffer;
if (!buffer.resize(packet.serialized_size()).is_error())
{
packet.serialize(buffer.span());
size_t total_sent = 0;
while (total_sent < buffer.size())
{
const ssize_t nsend = send(m_client_fd, buffer.data() + total_sent, buffer.size() - total_sent, 0);
if (nsend <= 0)
break;
total_sent += nsend;
}
}
close(m_client_fd);
}