summaryrefslogtreecommitdiff
path: root/WindowServer
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-15 11:43:43 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-15 11:43:43 +0100
commitfbcc8ab840aaa212934da0082a039038c8a81e53 (patch)
tree69b0ce0648d704e43f4e543d6a649e9b1ed8eb20 /WindowServer
parent29c49356e3229acb740f016d39629e322d31abd1 (diff)
downloadserenity-fbcc8ab840aaa212934da0082a039038c8a81e53.zip
WindowServer: Slurp all available client messages when checking them.
We were reading one client message per client per event loop iteration. That was not very snappy. Make the sockets non-blocking and read() until there are no messages left. It would be even better to make as few calls to read() as possible to reduce context switching, but this is already a huge improvement.
Diffstat (limited to 'WindowServer')
-rw-r--r--WindowServer/WSMessageLoop.cpp24
-rw-r--r--WindowServer/WSMessageLoop.h3
2 files changed, 15 insertions, 12 deletions
diff --git a/WindowServer/WSMessageLoop.cpp b/WindowServer/WSMessageLoop.cpp
index de550148c2..c9f75bdfba 100644
--- a/WindowServer/WSMessageLoop.cpp
+++ b/WindowServer/WSMessageLoop.cpp
@@ -40,7 +40,7 @@ int WSMessageLoop::exec()
m_server_process->sys$unlink("/wsportal");
- m_server_fd = m_server_process->sys$socket(AF_LOCAL, SOCK_STREAM, 0);
+ m_server_fd = m_server_process->sys$socket(AF_LOCAL, SOCK_STREAM | SOCK_NONBLOCK, 0);
ASSERT(m_server_fd >= 0);
sockaddr_un address;
address.sun_family = AF_LOCAL;
@@ -244,9 +244,17 @@ void WSMessageLoop::wait_for_message()
}
WSClientConnection::for_each_client([&] (WSClientConnection& client) {
if (bitmap.get(client.fd())) {
- byte buffer[4096];
- ssize_t nread = m_server_process->sys$read(client.fd(), buffer, sizeof(WSAPI_ClientMessage));
- on_receive_from_client(client.client_id(), buffer, nread);
+ for (;;) {
+ WSAPI_ClientMessage message;
+ // FIXME: Don't go one message at a time, that's so much context switching, oof.
+ ssize_t nread = m_server_process->sys$read(client.fd(), &message, sizeof(WSAPI_ClientMessage));
+ if (nread == 0)
+ break;
+ if (nread < 0) {
+ ASSERT_NOT_REACHED();
+ }
+ on_receive_from_client(client.client_id(), message);
+ }
}
});
}
@@ -313,18 +321,14 @@ void WSMessageLoop::notify_client_died(int client_id)
post_message(client, make<WSClientDisconnectedNotification>(client_id));
}
-ssize_t WSMessageLoop::on_receive_from_client(int client_id, const byte* data, size_t size)
+void WSMessageLoop::on_receive_from_client(int client_id, const WSAPI_ClientMessage& message)
{
// FIXME: This should not be necessary.. why is this necessary?
while (!running())
Scheduler::yield();
LOCKER(m_lock);
-
WSClientConnection* client = WSClientConnection::ensure_for_client_id(client_id);
-
- ASSERT(size == sizeof(WSAPI_ClientMessage));
- auto& message = *reinterpret_cast<const WSAPI_ClientMessage*>(data);
switch (message.type) {
case WSAPI_ClientMessage::Type::CreateMenubar:
post_message(client, make<WSAPICreateMenubarRequest>(client_id));
@@ -386,6 +390,4 @@ ssize_t WSMessageLoop::on_receive_from_client(int client_id, const byte* data, s
post_message(client, make<WSAPISetGlobalCursorTrackingRequest>(client_id, message.window_id, message.value));
break;
}
- server_process().request_wakeup();
- return size;
}
diff --git a/WindowServer/WSMessageLoop.h b/WindowServer/WSMessageLoop.h
index 51b064589d..338bf6c63e 100644
--- a/WindowServer/WSMessageLoop.h
+++ b/WindowServer/WSMessageLoop.h
@@ -9,6 +9,7 @@
class WSMessageReceiver;
class Process;
+struct WSAPI_ClientMessage;
struct WSAPI_ServerMessage;
class WSMessageLoop {
@@ -31,7 +32,7 @@ public:
int stop_timer(int timer_id);
void post_message_to_client(int client_id, const WSAPI_ServerMessage&);
- ssize_t on_receive_from_client(int client_id, const byte*, size_t);
+ void on_receive_from_client(int client_id, const WSAPI_ClientMessage&);
static Process* process_from_client_id(int client_id);
void notify_client_died(int client_id);