Commit graph

710 commits

Author SHA1 Message Date
Tim Schumacher 2470dd3bb5 AK: Move bit streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher 94f139c111 AK: Move buffered streams from LibCore 2023-01-29 19:16:44 -07:00
Tim Schumacher 8464da1439 AK: Move Stream and SeekableStream from LibCore
`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
2023-01-29 19:16:44 -07:00
Tim Schumacher 5f2ea31816 AK: Move Handle from LibCore and name it MaybeOwned
The new name should make it abundantly clear what it does.
2023-01-29 19:16:44 -07:00
Tim Schumacher ae64b68717 AK: Deprecate the old AK::Stream
This also removes a few cases where the respective header wasn't
actually required to be included.
2023-01-29 19:16:44 -07:00
Linus Groh 108ea2b921 LibCore: Remove try_ prefix from fallible SharedCircularQueue methods 2023-01-28 22:41:36 +01:00
Linus Groh 9c08bb9555 AK: Remove try_ prefix from FixedArray creation functions 2023-01-28 22:41:36 +01:00
Linus Groh 6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Sam Atkins 269ce258b4 LibCore: Replace uses of JsonObject::get_deprecated()/get_ptr() 2023-01-26 09:57:14 -05:00
Sam Atkins 00b897af8f LibCore: Add nice get/set_process_name() wrappers in Core::Process
`Process::get_name()` and `Process::set_name()` are basically the same
as `get_process_name()` and `set_process_name()`, except making use of
convenient Serenity standard types and returning ErrorOr, instead of
char* and errno shenanigans.

`Process::set_name()` has an optional `SetThreadName` parameter, for
when you also want to set the thread's name to the same thing. That's
true for the two places that use `set_process_name()`.
2023-01-25 14:27:45 +01:00
Karol Kosek b810f7f88a LibCore: Implement File::can_delete_or_move()
Besides from a general check if a file's directory has write
permissions, this also checks if the directory has set a sticky bit,
meaning that only file owners and the directory owner can remove or move
files in such directory. It's being used in /tmp for example.
2023-01-24 20:13:30 +00:00
Tim Schumacher 6ccda76a71 LibCore: Add support for non-trivial types to Stream::*_value
At the moment, there is no immediate advantage compared to just calling
the underlying functions directly, but having a common interface feels
more ergonomic (users don't have to care about how a type serializes)
and maybe we'll find a way to hide the actual implementation from direct
access some time in the future.
2023-01-24 12:47:39 +00:00
Tim Schumacher 0245614a4f LibCore: Remove FileStream 2023-01-20 20:50:42 +00:00
Ali Mohammad Pur 7d4a30af56 LibCore: Avoid logical OOB read in AllocatingMemoryStream::offset_of()
The previous impl was trimming the last chunk to the free space instead
of the used space, which yielded an OOB read if the needle wasn't found.
2023-01-20 20:34:31 +00:00
Liav A fedd18eb89 LibCore: Add MIME type string for TGA files 2023-01-20 15:13:31 +00:00
Liav A e77b110541 LibCore: Return StringView from guess_mime_type_based_on_filename method 2023-01-20 15:13:31 +00:00
Timothy Flynn 0dce7b72f9 LibCore: Implement FileWatcher for macOS
The macOS FileWatcher depends on macOS dispatch queues, which run on a
different thread than the Core::EventLoop. This implementation handles
filesystem events on its dispatch queue, then forwards the event back to
the main Core::EventLoop for notifying the FileWatcher owner.
2023-01-19 11:29:48 +00:00
Timothy Flynn 0e7a48bd7d LibCore: Allow subclassing FileWatcher
This will be handy for platforms which need to be able to store extra
OS-specific members. For example, macOS needs to store a dispatch queue,
and event stream, etc.
2023-01-19 11:29:48 +00:00
Tim Schumacher daf181caa8 LibCore: Let offset-related Stream functions return an unsigned value
A negative return value doesn't make sense for any of those functions.
The return types were inherited from POSIX, where they also need to have
an indicator for an error (negative values).
2023-01-19 11:41:56 +01:00
Tim Schumacher 1ca62de558 LibCore: Return EBADF on unsupported stream operations 2023-01-19 11:41:56 +01:00
Timothy Flynn 142abc0b2e LibCore+ConfigServer: Add FileWatcherFlags to replace InodeWatcherFlags
InodeWatcherFlags is an enumeration from the Kernel. To avoid using it
outside of Serenity, add a FileWatcherFlags for FileWatcher, much like
we already have FileWatcherEvent::Type.
2023-01-18 09:37:11 -05:00
Timothy Flynn 98e6dbf50a Userland: Add missing limits.h header includes
This is currently being implicitly including by InodeWatcherEvent.h by
way of FileWatcher.h. The former will soon be removed from the latter,
which would otherwise cause a compile error in these files.
2023-01-18 09:37:11 -05:00
Timothy Flynn 8ca528217c LibCore: Implement FileWatcher for Linux
This implements FileWatcher using inotify filesystem events. Serenity's
InodeWatcher is remarkably similar to inotify, so this is almost an
identical implementation.

The existing TestLibCoreFileWatcher test is added to Lagom (currently
just for Linux).

This does not implement BlockingFileWatcher as that is currently not
used anywhere but on Serenity.
2023-01-18 06:46:12 -05:00
Timothy Flynn 91cbdc67de LibCore: Default-initialize the FileWatcher event mask 2023-01-18 06:46:12 -05:00
Timothy Flynn 8419ca8b78 LibCore: Handle multiple events in the FileWatcher event mask formatter 2023-01-18 06:46:12 -05:00
Timothy Flynn 5bfc9daba1 LibCore: Move FileWatcher implementations into separate files
Rather than one big file with (eventually) all implementations for each
OS, let's keep OS-specific implementations in their own files.
2023-01-18 06:46:12 -05:00
Sam Atkins 1dd6b7f5b7 AK+Everywhere: Rename JsonObject::get() to ::get_deprecated()
This is a preparatory step to making `get()` return `ErrorOr`.
2023-01-17 19:52:52 -05:00
Tim Schumacher 0a563f4943 LibCore: Remove Stream::write_or_error
This was there for compatibility purposes and now it's no longer
needed.
2023-01-17 23:55:34 +01:00
Tim Schumacher add2e2c076 LibCore: Do short forward seeks by discarding bytes from the buffer
This saves us an actual seek and rereading already stored buffer data in
cases where the seek is entirely covered by the currently buffered data.
This is especially important since we implement `discard` using `seek`
for seekable streams.
2023-01-17 21:56:56 +01:00
Tim Schumacher bdf991fe76 LibCore: Calculate the correct seek offset for buffered streams 2023-01-17 21:56:56 +01:00
Lucas CHOLLET 2e52de5744 LibCore: Add Stream::File::fd()
Unlike `leak_fd()` the stream is still owning the file descriptor after
the call.
2023-01-16 17:05:41 +00:00
Tim Schumacher d1711f1cef AK: Define our own concept of "trivially serializable"
While at it, rename the `read_trivial_value` and `write_trivial_value`
functions to `read_value` and `write_value` respectively, since we'll
add compatibility for non-trivial types down the line.
2023-01-15 23:06:31 -05:00
Tim Schumacher 6777cb0975 LibCore: Fix up type mistakes in Stream::read_trivial_value 2023-01-15 23:06:31 -05:00
nipos bfacbe1e0d LibCore: Enable file descriptor passing on OpenBSD 2023-01-15 01:11:46 +00:00
Lucas CHOLLET 56512caa73 LibCore: Don't reject an empty buffer with ENOBUFS
Instead, we just return the empty buffer.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET 4402720a15 LibCore: Don't rely on \n detection to populate the buffer
We don't need to call `can_read_line()` as the buffer will be populated
by `find_and_populate_until_any_of()`. The change is also beneficial as
the buffer will be populated until a candidate is found and not
necessarily a new line.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET 8252436c18 LibCore: Resume search in find_and_populate_until_any_of
The search used to go through the buffer from the start, even if we just
appended a small number of bytes at the end. It now remembers the last
stop and resume the search from it.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET b21ea54af0 LibCore: Merge two search implementations in Stream::BufferedStream
`can_read_line()` and `read_until_any_of` used to have two different
implementations to search for a needle. This commit factorizes both
algorithms.
2023-01-14 16:20:30 -07:00
Lucas CHOLLET 9a7accddb7 AK: Add an optional starting offset to CircularBuffer::offset_of
This parameter allows to start searching after an offset. For example,
to resume a search.

It is unfortunately a breaking change in API so this patch also modifies
one user and one test.
2023-01-14 16:20:30 -07:00
nipos b510747e22 LibCore: On OpenBSD, handle anon_create() like on MacOS 2023-01-14 16:31:59 +01:00
Tim Schumacher 202175cf4c LibCore: Add helper functions to read/write trivial values from streams
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2023-01-13 18:41:05 -07:00
Niklas Poslovski 19bae983e4 LibCore: Enable file descriptor passing on FreeBSD
Ladybird currently doesn't render any webpages on FreeBSD and throws
hundreds of errors,beginning with this:
IPC::ConnectionBase (0x0000000805bf2b00) had an error (File descriptor
passing not supported on this platform), disconnecting.
WebContent process crashed!
2023-01-13 17:36:32 -07:00
Tim Schumacher 100112134d LibCore: Allow zero-sized spans in Stream::*_entire_buffer
There is no particular reason why we shouldn't allow zero-sized reads or
writes here, and this actually might cause issues with our common
stream-to-stream copy pattern if we end up at an unfortunate offset
where the next read would be zero-sized and trigger EOF only after that.
2023-01-13 17:34:45 -07:00
Tim Schumacher 156b6e83cd LibCore: Add AllocatingMemoryStream::offset_of 2023-01-14 00:33:35 +03:30
Arda Cinar 3f99a8734e LibCore: Call the mkstemp function in a slightly prettier way
This removes a FIXME, although the new version isn't less char-pointery.
2023-01-13 09:29:44 -05:00
Sam Atkins 6edc0cf5ab LibCore+Userland: Don't auto-start new Core::Timers
This was unintuitive, and only useful in a few cases. In the majority,
users had to immediately call `stop()`, and several who did want the
timer started would call `start()` on it immediately anyway. Case in
point: There are only two places I had to add a manual `start()`.
2023-01-12 11:25:51 +01:00
Sam Atkins a8cf0c9371 LibCore+Userland: Make Core::Timer::create_single_shot() return ErrorOr
clang-format sure has some interesting opinions about where to put a
method call that comes after a lambda. :thonk:
2023-01-12 11:25:51 +01:00
Sam Atkins a15d44f019 LibCore+Userland: Make Core::Timer::create_repeating() return ErrorOr
The FIXMEs must flow!
2023-01-12 11:25:51 +01:00
Linus Groh c5cadca542 LibCore: Add StandardPaths::font_directories()
This provides a list of well-known directories containing font files,
e.g. for use with Gfx::FontDatabase::load_all_fonts_from_path().
2023-01-11 20:54:49 +00:00
kleines Filmröllchen 2475f6a641 LibCore: Explain EventLoop and reorder some members in the header
This hopefully makes EventLoop easier to understand.
2023-01-11 11:49:05 +01:00