Commit graph

77 commits

Author SHA1 Message Date
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00
Lenny Maiorani
e6f907a155 AK: Simplify constructors and conversions from nullptr_t
Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
2021-01-12 09:11:45 +01:00
AnotherTest
bdd4b99d72 LibIPC: Add an on_destruction hook to IPC::Message
Any cleanup of resources needed (up until the message is sent) can be
done here.
Currently, the only such resource is an IPC::File.
2020-12-30 20:37:41 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Andreas Kling
0e4ecca336 LibIPC: Remove use of ByteBuffer::wrap()
ByteBuffer::wrap() was useful before we had Span. Let's see if we can't
get rid of some more ByteBuffer wrapping.
2020-12-19 11:30:02 +01:00
Linus Groh
41d042cc86 LibIPC: Fix 'unused private member' error when building with clang
This was breaking the Lagom build when using clang, as m_sockfd's only
use is behind an #ifdef __serenity__. (void) it elsewhere to fix that.
2020-11-25 20:00:23 +01:00
Sergey Bugaev
23dc3ff0c2 LibIPC: Support sending file descriptors :^)
It is now possible to use the special IPC::File type in message arguments. In
C++, the type is nothing more than a wrapper over a file descriptor. But when
serializing/deserializing IPC::File arguments, LibIPC will use the sendfd/recvfd
kernel APIs instead of sending the integer inline.

This makes it quite convenient to pass files over IPC, and will allow us to
significantly tighten sandboxes in the future :^)

Closes https://github.com/SerenityOS/serenity/issues/3643
2020-11-23 18:37:40 +01:00
Sergey Bugaev
fa2e3e2be4 LibIPC: Prepend each message with its size
This makes it much simpler to determine when we've read a complete message, and
will make it possible to integrate recvfd() in the future commit.
2020-11-23 18:37:40 +01:00
AnotherTest
c930e02624 LibIPC: Add support for passing around ByteBuffers and HashMap<K, V>
It should be noted that using a shared buffer should still be preferred
over passing a raw ByteBuffer over the wire.
2020-11-08 21:46:13 +01:00
Andreas Kling
9103471863 LibIPC: Handle partial messages
Since we're using byte streamed Unix sockets for the IPC protocols,
it's possible for the kernel to run out of socket buffer space with
a partial message near the end of the buffer.

Handle this situation in IPC::Connection by buffering the bytes of
what may be a partial message, and prepending them to the incoming
data next time we receive from the peer.

This fixes WindowServer asserting when a peer is spamming it hard.
2020-10-25 11:37:42 +01:00
AnotherTest
b42c6ea281 LibIPC: Make IPC::encode() and ::decode() fail at compiletime when used
This would previously fail at runtime, and it would have zero indication
of what exactly went wrong.
Also adds `AK::DependentFalse<Ts...>', which is a...dependent false.
2020-10-04 23:12:28 +02:00
Andreas Kling
6c9a3ecf42 LibIPC: Silence a warning when compiling with gcc -O0 2020-10-01 19:16:35 +02:00
asynts
c879ecf509 LibIPC: Use InputMemoryStream instead of BufferStream. 2020-09-21 09:37:49 +02:00
Tom
5ee29e8a26 LibIPC: Check if socket is still open before using socket descriptor
Writing to the socket may trigger a close of the socket descriptor
if a disconnect was detected. We need to check if it is still valid
when waiting for a response after attempting to send a synchronous
message.

Fixes #3515
2020-09-17 09:47:29 +02:00
Tom
d55e3c4642 LibIPC: Disable Notifier before closing socket
Because we're closing a file descriptor, we need to disable any
Notifier that is using it so that the EventLoop does not use invalid
file descriptors.

Fixes #3508
2020-09-16 17:50:43 +02:00
Andreas Kling
8d574c7363 LibIPC: Remove unused DisconnectedEvent mechanism
This was previously used to defer handling disconnections until the
next event loop iteration. We now achieve the same with simple use
of deferred_invoke(). :^)
2020-09-12 14:49:29 +02:00
Andreas Kling
4873e2bb53 LibIPC: Move notifier handling entirely to IPC::Connection base class 2020-09-12 14:49:29 +02:00
Andreas Kling
54116115a8 LibIPC: Remove debug spam on disconnection 2020-09-12 14:49:29 +02:00
Andreas Kling
aba793fb3e LibIPC: Share most of the code between {Client,Server}Connection
This patch introduces IPC::Connection which becomes the new base class
of ClientConnection and ServerConnection. Most of the functionality
has been hoisted up to the base class since almost all of it is useful
on both sides.

This gives us the ability to send synchronous messages in both
directions, which is needed for the WebContent server process.
Unlike other servers, WebContent does not mind blocking on a response
from its client.
2020-09-12 14:49:29 +02:00
Andreas Kling
2e6d59b7b2 Clipboard: Add a key-value map alongside the clipboard storage
A clipping now consists of three things:

- The raw clip data
- A MIME type
- A key-value map (String, String) for anything you like
2020-09-05 16:52:24 +02:00
Tom
8b0b653471 LibIPC: Fix waiting for specific message
When waiting for a specific message, only consider messages
from the peer endpoint. Otherwise a message with the same id
for the local endpoint may be misinterpreted.

This fixes the Terminal sometimes hanging after bootup because
a local endpoint message is mistaken for the CreateMenuResponse
message.
2020-08-03 15:59:11 +02:00
Andreas Kling
cb47ab15ec LibIPC: Tweak a misleading perror()
If we get an error from recv(), let's blame "recv" instead of "read".
2020-07-15 18:47:45 +02:00
Andreas Kling
94ddb07e58 LibIPC+Services: Make ClientConnection take socket as NonnullRefPtr
This avoids getting into the awkward situation where the socket is
still part-owned by main() in multi-instance service. Also it just
reads nicer.
2020-07-06 13:30:11 +02:00
Andreas Kling
80d800e6d4 LibIPC: Don't assert on short writes in IPC::ClientConnection
This stops servers from crashing when a client's socket buffer becomes
full and we can't post any more messages to it. Normally this means the
client process is hanged/spinning, but I suppose this could also happen
under severe system load.

It's unclear to me what a better solution here would be. We can't keep
buffering messages indefinitely if the client is just never going to
receive them anyway. At some point we have to cut our losses, and it
seems pretty reasonable to let the kernel socket buffer be the cutoff.

It will be the responsibility of the individual server implementations
to avoid sending messages to clients that may be unable to handle them.
2020-07-03 14:05:09 +02:00
Andreas Kling
b273b31c7d LibIPC: Silence some debug spam 2020-06-22 21:47:01 +02:00
Andreas Kling
ed351c7493 LibIPC: Add setters for overriding the client/server PID if needed
Since SO_PEERCRED can only tell us who originally accepted the socket
on the other side, we'll sometimes need to negotiate PID info manually.
2020-06-21 21:54:30 +02:00
Andreas Kling
4ab1b0b436 LibIPC: Only start responsiveness timer after sending client a message
Instead of always running the responsiveness timer for IPC clients,
we now only start it after sending a message. This avoids waking up
otherwise idle clients to do ping/pong busywork.
2020-06-13 13:47:01 +02:00
Kevin Meyer
88673f3f85 LibIPC: Use create_single_shot to construct timer 2020-06-12 18:29:55 +02:00
Andreas Kling
6f1b5fc0ab LibIPC: Actually use the new Core::Timer::restart() I just added
Thanks @brynet for noticing. :^)
2020-06-12 09:13:27 +02:00
Andreas Kling
2ce2c4810a LibIPC+WindowServer+LibGUI: Detect and highlight unresponsive GUI apps
IPC::ClientConnection now tracks the time since the last time we got
a message from the client and calls a virtual function on itself after
3 seconds: may_have_become_unresponsive().

Subclasses of ClientConnection can then react to this if they like.

We use this mechanism in WindowServer to send out a friendly Ping
message to the client. If he doesn't Pong within 1 second, we mark
the client as "unresponsive" and recompose all of his windows with
a darkened appearance and amended title until he Pongs us.

This is a little on the aggressive side and we should figure out a way
to wake up less often. Perhaps this could only be done to windows the
user is currently interacting with, for example.

Anyways, this is pretty cool! :^)
2020-06-11 22:46:49 +02:00
Sergey Bugaev
fc481552f5 LibIPC+LibGfx+IPCCompiler: Drop some unused includes 2020-06-08 13:58:32 +02:00
Andreas Kling
3654710c41 LibIPC+Services: Support URL as a native IPC type 2020-06-07 22:55:33 +02:00
Sergey Bugaev
8449f0a15b LibIPC: Fix server crashes on client disconnects
The server should always survive client communication errors.
2020-05-30 22:31:08 +02:00
Sergey Bugaev
450a2a0f9c Build: Switch to CMake :^)
Closes https://github.com/SerenityOS/serenity/issues/2080
2020-05-14 20:15:18 +02:00
Andreas Kling
413ab652c8 LibIPC+IPCCompiler: Templatize encoding/decoding of Optional<T>
This was the last one! IPCCompiler no longer has any type-specific
encoding/decoding logic! :^)
2020-05-12 19:04:05 +02:00
Andreas Kling
3775983dfe LibIPC+LibGfx: Templatize IPC encoding as well as decoding
Now most classes dictate how they are serialized and deserialized when
transmitted across LibIPC sockets. This also makes the IPC compiler
a bit simpler. :^)
2020-05-12 18:49:24 +02:00
Linus Groh
54c4cd8a66 Meta: Delete empty .cpp files 2020-05-09 23:45:16 +02:00
Andreas Kling
25db315b29 LibIPC: Use NonnullOwnPtrVector<Message> in IPC::ServerConnection
We never want to store null messages, so make it impossible to do so.
2020-05-08 21:40:06 +02:00
Andreas Kling
78943f031e LibIPC: Add a simple IPC::Dictionary type (String key -> String value) 2020-05-03 23:01:58 +02:00
Sergey Bugaev
628777f94a LibIPC: Abort on connection failure
...instead of looping for (effectively) ever.

Fixes https://github.com/SerenityOS/serenity/issues/1869
2020-05-02 15:59:37 +02:00
Andreas Kling
4f200def9c AK: Stop allowing implicit downcast with OwnPtr and NonnullOwnPtr
Same issue here as we had with RefPtr and NonnullRefPtr.

Since we can't make copies of an owning pointer, we don't get quite the
same static_ptr_cast<T> here. Instead I've only added a new templated
version of OwnPtr::release_nonnull() in this patch, to solve the only
issue that popped up.

I'm not sure what the best solution here is, but this works for now.
2020-04-05 11:32:30 +02:00
Andreas Kling
24a0354ce8 LibIPC+LibGfx: Pass the IPC::Decoder to decoding helpers
Instead of passing the BufferStream, pass the Decoder. I'd like to stop
using BufferStream eventually anyway, so it's good to get it out of any
API's where it's in currently.
2020-03-29 19:37:23 +02:00
Andreas Kling
01ff36a2f4 LibIPC: Add forwarding header for LibIPC 2020-03-29 19:37:23 +02:00
Andreas Kling
22d0a6d92f AK: Remove unnecessary casts to size_t, after Vector changes
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
2020-03-01 12:58:22 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Andreas Kling
2143da6434 LibGUI: Add forwarding header
This patch adds <LibGUI/Forward.h> and uses it a bunch.
It also dragged various header dependency reduction changes into it.
2020-02-16 09:41:56 +01:00
Andreas Kling
a4d857e3c5 LibIPC+IPCCompiler: Add IPC::Decoder, let classes decode themselves
This shaves ~5 seconds off of a full build, not too bad. Also it just
seems nicer to push this logic out to classes. It could be better but
it's a start. :^)
2020-02-15 12:11:19 +01:00
Andreas Kling
2ae9a56c3f LibIPC: Move IPC::Encoder functions out of line
Compiling anything that includes generated IPC messages is painfully
slow at the moment. This moves the encoding helpers out of line, which
helps a bit. Doing the same for decoding will help more.
2020-02-15 12:10:48 +01:00
Andreas Kling
ef01af1cb2 LibIPC+IPCCompiler: Remove some unused members from generated messages 2020-02-15 12:10:48 +01:00