mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
WindowServer+LibGUI: Wait for the extra_data to arrive.
Since the sockets we use are non-blocking, just slap a select before the second call to read(). This fixes some flakiness seen under load. This should eventually work a bit differently, we could use recv() once it has MSG_WAITALL, and we should not let WindowServer handle all the client connections on the main thread. But for now, this works. Fixes #24.
This commit is contained in:
parent
ded3652f6c
commit
288e97a206
Notes:
sideshowbarker
2024-07-19 14:23:49 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/288e97a2063
2 changed files with 17 additions and 0 deletions
|
@ -341,6 +341,12 @@ bool GEventLoop::drain_messages_from_server()
|
|||
ByteBuffer extra_data;
|
||||
if (message.extra_size) {
|
||||
extra_data = ByteBuffer::create_uninitialized(message.extra_size);
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(s_event_fd, &rfds);
|
||||
struct timeval timeout { 1, 0 };
|
||||
int rc = select(s_event_fd + 1, &rfds, nullptr, nullptr, &timeout);
|
||||
ASSERT(rc == 1);
|
||||
int extra_nread = read(s_event_fd, extra_data.data(), extra_data.size());
|
||||
ASSERT(extra_nread == message.extra_size);
|
||||
}
|
||||
|
|
|
@ -309,6 +309,17 @@ void WSEventLoop::drain_client(WSClientConnection& client)
|
|||
}
|
||||
|
||||
extra_data = ByteBuffer::create_uninitialized(message.extra_size);
|
||||
|
||||
fd_set rfds;
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(client.fd(), &rfds);
|
||||
struct timeval timeout { 1, 0 };
|
||||
int rc = select(client.fd() + 1, &rfds, nullptr, nullptr, &timeout);
|
||||
if (rc != 1) {
|
||||
dbgprintf("extra_data didn't show up in time\n");
|
||||
return client.did_misbehave();
|
||||
}
|
||||
|
||||
int extra_nread = read(client.fd(), extra_data.data(), extra_data.size());
|
||||
if (extra_nread != message.extra_size) {
|
||||
dbgprintf("extra_nread(%d) != extra_size(%d)\n", extra_nread, extra_data.size());
|
||||
|
|
Loading…
Reference in a new issue