Kernel: Add a writev() syscall for writing multiple buffers in one go.

We then use this immediately in the WindowServer/LibGUI communication in
order to send both message + optional "extra data" with a single syscall.
This commit is contained in:
Andreas Kling 2019-05-10 03:19:25 +02:00
parent e6443649cb
commit 99aead4857
Notes: sideshowbarker 2024-07-19 14:11:09 +09:00
8 changed files with 111 additions and 54 deletions

View file

@ -19,6 +19,7 @@
#include <LibC/errno.h>
#include <LibC/string.h>
#include <LibC/stdlib.h>
#include <sys/uio.h>
//#define GEVENTLOOP_DEBUG
//#define COALESCING_DEBUG
@ -359,13 +360,20 @@ bool GEventLoop::post_message_to_server(const WSAPI_ClientMessage& message, cons
if (!extra_data.is_empty())
const_cast<WSAPI_ClientMessage&>(message).extra_size = extra_data.size();
int nwritten = write(s_event_fd, &message, sizeof(WSAPI_ClientMessage));
ASSERT(nwritten == sizeof(WSAPI_ClientMessage));
struct iovec iov[2];
int iov_count = 1;
iov[0].iov_base = (void*)&message;
iov[0].iov_len = sizeof(message);
if (!extra_data.is_empty()) {
nwritten = write(s_event_fd, extra_data.data(), extra_data.size());
ASSERT(nwritten == extra_data.size());
iov[1].iov_base = (void*)extra_data.data();
iov[1].iov_len = extra_data.size();
++iov_count;
}
int nwritten = writev(s_event_fd, iov, iov_count);
ASSERT(nwritten == sizeof(message) + extra_data.size());
return true;
}