diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-05-01 18:25:24 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-05-01 18:28:33 +0200 |
commit | 288e97a20634defbe56dcec698a108025be2c64b (patch) | |
tree | 1dac967cf87a23d363efbcc068c9c37d28f28567 | |
parent | ded3652f6cfa672340191daeba25fdf476fc4dad (diff) | |
download | serenity-288e97a20634defbe56dcec698a108025be2c64b.zip |
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.
-rw-r--r-- | LibGUI/GEventLoop.cpp | 6 | ||||
-rw-r--r-- | Servers/WindowServer/WSEventLoop.cpp | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/LibGUI/GEventLoop.cpp b/LibGUI/GEventLoop.cpp index cc97d9323a..5731d30387 100644 --- a/LibGUI/GEventLoop.cpp +++ b/LibGUI/GEventLoop.cpp @@ -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); } diff --git a/Servers/WindowServer/WSEventLoop.cpp b/Servers/WindowServer/WSEventLoop.cpp index 8a2e0a28aa..745d88b9e2 100644 --- a/Servers/WindowServer/WSEventLoop.cpp +++ b/Servers/WindowServer/WSEventLoop.cpp @@ -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()); |