Commit graph

207 commits

Author SHA1 Message Date
Andreas Kling
a292d8cd5a LibCore: Add CFileStreamReader, a simple streaming CFile reader.
This is extremely barebones right now, but can be used to easily read binary
data from a CFile piece by piece.
2019-07-27 16:38:44 +02:00
Andreas Kling
9ed7f4576b CIODevice: Try to preallocate the exact needed buffer size in read_all().
If we can get the exact file size from fstat(), it's a very good idea to use
it since it means we avoid eleventy thousand reallocations.
2019-07-27 14:24:19 +02:00
Andreas Kling
e7957db173 LibCore: Remove CSocket's bind() and listen().
We're going to be using dedicated server socket classes instead.
This was only implemented for CLocalSocket, and clients have been switched
over to using CLocalServer.
2019-07-27 10:58:21 +02:00
Andreas Kling
fe45f5a6d2 LibCore: Port CoreIPCServer to using CLocalServer.
Use CLocalServer to listen for connections in WindowServer and AudioServer.
This allows us to accept incoming CLocalSocket objects from the CLocalServer
and construct client connections based on those.

Removed COpenedSocket since it's replaced by CLocalSocket.
2019-07-27 10:53:50 +02:00
Andreas Kling
c289e49ee5 LibCore: Use clang-format on CoreIPC{Client,Server}. 2019-07-27 10:50:26 +02:00
Andreas Kling
82446ea701 CSocket: Add an on_ready_to_read callback.
This callback uses a CNotifier internally and will fire whenever there's
something to be read from the socket.
2019-07-27 10:48:43 +02:00
Andreas Kling
8f4fba95c0 CIODevice: Add a virtual did_update_fd() no notify subclasses of fd change.
This will allow subclasses to react when the file descriptor changes.
2019-07-27 10:47:46 +02:00
Andreas Kling
b3fe9cde52 LibCore: Add CLocalServer, a server-only local socket class.
Instead of trying to support both client and server in CLocalSocket, let's
have a specialized server class.

The basic usage is:

    CLocalServer server;
    server.listen("/tmp/name-of-portal");
    server.on_ready_to_accept = [&] {
        CLocalSocket* client = server.accept();
        ...
    };

This will make things a lot simpler, since an accepting socket doesn't need
half of the stuff that a regular CIODevice provides. :^)
2019-07-27 10:32:40 +02:00
Andreas Kling
10c35d345a LibCore: Add comment about child events for partially-constructed children.
Since ChildAdded events originate from the CObject constructor, they are not
fully constructed when their parent learns that they were added.
Added a little comment about this to the child_event() declaration.
2019-07-27 09:31:46 +02:00
Andreas Kling
be2b585ca6 LibCore: Add CSocket::bind() (virtual) and CSocket::listen().
These will be useful for implementing server sockets.
2019-07-26 22:39:16 +02:00
Andreas Kling
7da5a04131 CEventLoop: Convert dbgprintf() to dbg(). 2019-07-26 16:00:56 +02:00
Andreas Kling
a599317624 LibCore: Introduce a C_OBJECT macro.
This macro goes at the top of every CObject-derived class like so:

class SomeClass : public CObject {
    C_OBJECT(SomeClass)
public:
    ...

At the moment, all it does is create an override for the class_name() getter
but in the future this will be used to automatically insert member functions
into these classes.
2019-07-25 19:49:28 +02:00
Andreas Kling
d21a4f7518 CEventLoop: Don't re-process already processed events when un-nesting.
If we had already processed a couple of queued events by the time we were
told to un-nest the event loop, we'd put the entire current batch at the
head of the outer queue. This meant that we might end up trying to process
the same events multiple times.

Let's not do that. :^)
2019-07-25 16:12:51 +02:00
Andreas Kling
f46a1377ac CSocket: Add missing <sys/un.h> include to fix host build. 2019-07-25 11:49:08 +02:00
Andreas Kling
16bcaf08a3 CSocket: Fix Clang warning about unused private member m_type. 2019-07-25 11:48:21 +02:00
Andreas Kling
e940d4b07b LibCore: Only build CThread on Serenity platforms. 2019-07-25 11:47:53 +02:00
Andreas Kling
1d0b464618 AK: Make HashMap::get(Key) return an Optional<Value>.
This allows HashMap::get() to be used for value types that cannot be default
constructed (e.g NonnullOwnPtr.)
2019-07-24 10:25:43 +02:00
Andreas Kling
93489fbc4c Convert HashMap<Key, OwnPtr<T>> to HashMap<Key, NonnullOwnPtr<T>>.
In every case I found, we never wanted to support null entry values.
With NonnullOwnPtr, we can encode that at the type level. :^)
2019-07-24 08:42:55 +02:00
Andreas Kling
3c5befde36 CEventLoop: Use NonnullOwnPtr for QueuedEvent::event.
We don't allow null events in the event queue. :^)
2019-07-24 08:38:28 +02:00
Andreas Kling
66646081b7 CEventLoop: Avoid undefined evaluation order in register_timer(). 2019-07-23 14:55:12 +02:00
Andreas Kling
0ef13e60b0 Libraries: Fix wrong paths to "Root" in the various install.sh scripts.
We were installing libraries into /Libraries/Root, rather than in /Root.
This made the ports system behave rather unpredictable, since I had old
versions of things in /Root and new versions of things in /Libraries/Root.
2019-07-21 21:38:30 +02:00
Andreas Kling
c7ea94697e Libraries: Remove unused "install" targets.
We've been using a per-directory "install.sh" for some time, so let's get
rid of the old way of doing things.
2019-07-21 21:28:48 +02:00
Robin Burchell
f2c0e55070 Userspace: Deal with select() returning EINTR on a signal interruption
Add a trivial CSafeSyscall template that calls a callback until it stops
returning EINTR, and use it everywhere we use select() now.

Thanks to Andreas for the suggestion of using a template parameter for
the syscall function to invoke.
2019-07-21 14:27:14 +02:00
Andreas Kling
98b569a702 CEventLoop: Skip over null events in the queue.
Added some FIXME's about correctness issues in nested event loop exiting.
2019-07-21 10:18:00 +02:00
Andreas Kling
046f00f77e CEventLoop: Use Vector::prepend(Vector&&) to shuffle events to outer loop.
When exiting a nested event loop, we prepend any unprocessed events to the
outer loop's event queue.
2019-07-20 16:11:45 +02:00
Andreas Kling
26c29e59ec CEventLoop: Remove some no-longer-used virtuals. 2019-07-20 15:50:03 +02:00
Andreas Kling
1c0669f010 LibDraw: Introduce (formerly known as SharedGraphics.)
Instead of LibGUI and WindowServer building their own copies of the drawing
and graphics code, let's it in a separate LibDraw library.

This avoids building the code twice, and will encourage better separation
of concerns. :^)
2019-07-18 10:18:16 +02:00
Robin Burchell
57da716be0 ps: Port to using CProcessStatisticsReader and /proc/all
Drop /proc/summary in the process.
We only needed one new field here, thankfully, so this was quite straightforward.
2019-07-18 07:23:26 +02:00
Robin Burchell
a9d1a86e6e CProcessStatisticsReader: Be consistent about terminology from the kernel down 2019-07-18 07:23:26 +02:00
Robin Burchell
9c8dd836fc Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic
("Connection") term without clashing, which is way easier to understand
than to try to come up with unique names for both.
2019-07-17 20:16:44 +02:00
Robin Burchell
2177594c96 Port LibGUI to use CIPCClientSideConnection
As a consequence, move to use an explicit handshake() method rather than
calling virtuals from the constructor. This seemed to not bother
AClientConnection, but LibGUI crashes (rightfully) because of it.
2019-07-17 20:16:44 +02:00
Robin Burchell
41bece0682 Make AClientConnection generic 2019-07-17 20:16:44 +02:00
Robin Burchell
6eaa6826fa Port WSClientConnection to CIPCServerSideClient 2019-07-17 20:16:44 +02:00
Robin Burchell
edcbba9e98 Introduce CIPCServerSideClient
As a new base class of IPC connections server-side.
Port ASClientConnection to CIPCServerSideClient.
2019-07-17 20:16:44 +02:00
Robin Burchell
d8387f1506 CNotifier: Turn into a CObject and Use the event queue to deliver events
This way, CNotifier can mutate state to its little heart's content
without destroying the world when the global CNotifier hash changes
during delivery.
2019-07-16 20:47:32 +02:00
Robin Burchell
a714fc661d LibCore: Add a way to mark a socket as blocking (or not)
If custom I/O is being done outside CIODevice, we need a way to force blocking sometimes.
This also fixes the default of CLocalSocket to be non-blocking, the same
as CTCPSocket.
2019-07-16 20:22:54 +02:00
Robin Burchell
7bf420d83d CNotifier: Provide a way to unregister a notifier temporarily 2019-07-16 15:23:57 +02:00
Robin Burchell
e922db68d8 CSocket: Also call on_connected for local socket connections 2019-07-16 13:18:37 +02:00
Robin Burchell
14b2f90920 LibCore: Always call on_connected whether the connection was synchronous or not
It's unreasonable to expect the client to have to call it themselves if
the connection was immediate (local).
2019-07-16 13:18:37 +02:00
Robin Burchell
cd497accbe CLocalSocket: Add missing pragma once 2019-07-14 15:29:59 +02:00
Andreas Kling
e8d61bb8c0 CEventLoop: Oops, I had the pipe reader/writer fd's mixed up. 2019-07-14 14:28:24 +02:00
Andreas Kling
4c0c93ce09 LibCore: Oops, fix infinite recursion in LogStream << CSocketAddress. 2019-07-14 14:24:37 +02:00
Andreas Kling
c9ee481cdf LibCore: Port CSocket over to using dbg().
Also added a LogStream operator<< for CSocketAddress.
2019-07-14 11:02:40 +02:00
Andreas Kling
b4329a8eec CObject: Add LogStream operator<< for CObject. 2019-07-14 10:59:26 +02:00
Andreas Kling
a634fab3c4 CObject: Add custom_event() virtual.
This way you can just override custom_event() to catch CCustomEvent instead
of having to filter the entire event stream with event(). :^)
2019-07-14 10:27:27 +02:00
Andreas Kling
17ee548bcd CEventLoop: Add wake(), a mechanism for waking up when blocked in select().
This patch generalizes the concept used in Piano to wake up the event loop
so it can react to something happening on a secondary thread.
Basically, there's a pipe who is always part of the file descriptor set we
pass to select(), and calling wake() simply writes a little to that pipe.
2019-07-14 10:20:57 +02:00
Andreas Kling
f1d6a37d5d LibCore: Add CThread, a simple thread abstraction object.
Currently this is only a simple wrapper around create_thread() that
remembers the thread ID of the spawned thread.
2019-07-14 10:19:51 +02:00
Robin Burchell
ffa8cb668f AudioServer: Assorted infrastructure work
* Add a LibAudio, and move WAV file parsing there (via AWavFile and AWavLoader)
* Add CLocalSocket, and CSocket::connect() variant for local address types.
  We make some small use of this in WindowServer (as that's where we
  modelled it from), but don't get too invasive as this PR is already
  quite large, and the WS I/O is a bit carefully done
* Add an AClientConnection which will eventually be used to talk to
  AudioServer (and make use of it in Piano, though right now it really
  doesn't do anything except connect, using our new CLocalSocket...)
2019-07-13 22:57:24 +02:00
Andreas Kling
302cae5c2f CEventLoop: When asked to exit the event loop, exit right away.
Don't process any more events. We already prepend the remaining events in
this loop to the outer loop if needed.

If there were any more events queued after the exit request, the iteration
code would make an invalid access into 'queued_events'.

Fixes #300.
2019-07-13 19:54:57 +02:00
Andreas Kling
debc587ce2 LibCore: Add CCustomEvent, a custom CEvent for arbitrary use.
For convenience it includes an int, and a void*. Interpretation of the
contents is up to the client.
2019-07-13 18:35:13 +02:00
Andreas Kling
b06d2c04dc CObject: Add a "name" property.
This will be useful for things like the VisualBuilder code generator.
2019-07-10 20:33:53 +02:00
Andreas Kling
c33766f039 LibCore: Tweak slightly-off error message in CProcessStatisticsReader. 2019-07-10 15:32:30 +02:00
Andreas Kling
01216f3c3f Userland+LibCore: Use CProcessStatisticsReader to implement top.
Also tweaked CProcessStatisticsReader a bit to simplify the API.
2019-07-10 13:56:28 +02:00
Andreas Kling
0e75aba7c3 StringView: Rename characters() to characters_without_null_termination().
This should make you think twice before trying to use the const char* from
a StringView as if it's a null-terminated string.
2019-07-08 15:38:44 +02:00
Andreas Kling
56563cb305 CDirIterator: Fix another instance of StringView::characters() misuse. 2019-07-08 14:03:19 +02:00
Andreas Kling
8b0953a795 Libraries: Unbreak "make install" with new directory locations. 2019-07-04 16:41:42 +02:00
Andreas Kling
04b9dc2d30 Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch
moves the Lib*/ directories into Libraries/.
2019-07-04 16:16:50 +02:00