Commit Graph

190 Commits

Author SHA1 Message Date
Ali Mohammad Pur
b0a9c5673e LibHTTP: Respect the 'Connection: close' header on keep-alive jobs
If the server responds with this header, we _must_ close the connection,
as the server is allowed to ignore the socket and not respond to
anything past that response.
Fixes some RequestServer spins.
2021-09-30 11:46:37 +02:00
Karol Kosek
484f6a7cfa LibCore: Buffer small byte reads
Prior this change, if you had a program which frequently reads small
amount of bytes, then it would constantly fire up syscalls.

This patch sets that the minimum size that is passed to the read syscall
is 1024 and then it saves these additional bytes in a buffer for next
reads, which greatly improves the cpu usage on such cases.

In other words: reading flacs is now very efficient.
2021-09-27 16:31:28 +02:00
Karol Kosek
48a925b1d2 LibCore: Add optional custom read size argument in populate_read_buffer
This is a small preparation so IODevice::read() can use it in the next
commit.
2021-09-27 16:31:28 +02:00
Andreas Kling
f2b9ec9f8a LibCore: Add Core::EventLoop::spin_until(Function<bool()>)
This function spins the event loop until a goal condition is met.
2021-09-25 19:32:14 +02:00
Ali Mohammad Pur
bd4f7421cf LibCore: Don't double-check select() in Socket's read notifier callback
This was used to work around a possible bug where select() would mark a
socket readable, but another user of the same socket would read before
the notifier's callback is run; let's remove this and fix any issues
regarding that specific situation later when they pop up.
2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
81a0301d4d LibCore+RequestServer: Ignore callbacks for cancelled network jobs
Also cancel the jobs when they're destroyed.
This makes sure that jobs whose owners have discarded don't end up
crashing because of a did_fail().
2021-09-19 21:10:23 +04:30
Ali Mohammad Pur
65f7e45a75 RequestServer+LibHTTP+LibGemini: Cache connections to the same host
This makes connections (particularly TLS-based ones) do the handshaking
stuff only once.
Currently the cache is configured to keep at most two connections evenly
balanced in queue size, and with a grace period of 10s after the last
queued job has finished (after which the connection will be dropped).
2021-09-19 21:10:23 +04:30
Mustafa Quraish
0f749681a9 Everywhere: Use my fancy new serenityos.org email :^) 2021-09-13 20:51:50 +00:00
Brian Gianforcaro
b8cad2c9b9 LibCore: Switch to AK::secure_zero instead of platform specific APIs 2021-09-13 00:02:42 +02:00
Brian Gianforcaro
a2ee387683 LibCore: Add factory to create and start a new ElapsedTimer
Simplifies one of the main usage patterns of the timer class.
2021-09-12 17:24:44 +00:00
Mustafa Quraish
500a3fb2a7 Core/SecretString: Use memset_s instead of explicit_bzero on MacOS
MacOS doesn't have `explicit_bzero`, so this was causing errors when
compiling LibCore on the host.
2021-09-12 17:11:45 +00:00
Brian Gianforcaro
871ef7a735 AK+LibCore: Standardize on AK_OS_MACOS instead of __APPLE__
We use our custom platform definitions in most places, remove
the few remaining places we weren't using `AK_OS_MACOS`.
2021-09-12 18:31:10 +02:00
Brian Gianforcaro
1d4be9ca33 LibCore: Enable elapsed time as AK::Time on a ElapsedTimer 2021-09-12 16:39:23 +02:00
Brian Gianforcaro
df04283d61 LibCore: Make Account::authenticate take a SecretString
To encourage users to use the SecretString API, change the API so that
Account::authenticate only accepts a SecretString.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
9e667453c7 LibCore: Make get_password return SecretString instead of String
We shouldn't let secrets sit around in memory, as they could potentially
be retrieved by an attacker, or left in memory during a core dump.
2021-09-12 16:36:52 +02:00
Brian Gianforcaro
3bf6902790 LibCore: Add SecretString, a buffer that is zero'd on destruction
We have a few places where we read secrets into memory, and then
do some computation on them. In these cases we should always make
sure we zero the allocations before they are free'd.

The SecureString wrapper provides this abstraction by wrapping a
ByteBuffer and calling explicit_bzero on destruction of the object.
2021-09-12 16:36:52 +02:00
Callum Walker
fd3735199b LibCore: Fix link_file inverting src and dst paths on duplicate names
File::link_file takes the dst_path then the src_path so on duplicate
names we tried to create a link at the original file location, which
then flipped the parameters back round again and we ended up with a
broken link from "dst_path (1)" to "src_path (1)".
2021-09-12 04:58:22 +00:00
Ben Wiederhake
2e4ec891da Everywhere: Fix format-vulnerabilities
Command used:
grep -Pirn '(out|warn)ln\((?!["\)]|format,|stderr,|stdout,|output, ")' \
     AK Kernel/ Tests/ Userland/
(Plus some manual reviewing.)

Let's pick ArgsParser as an example:
    outln(file, m_general_help);
This will fail at runtime if the general help happens to contain braces.

Even if this transformation turns out to be unnecessary in a place or
two, this way the code is "more obviously" correct.
2021-09-11 15:16:26 +01:00
Ali Mohammad Pur
5a0cdb15b0 AK+Everywhere: Reduce the number of template parameters of IntrusiveList
This makes the user-facing type only take the node member pointer, and
lets the compiler figure out the other needed types from that.
2021-09-10 18:05:46 +03:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Mahmoud Mandour
7742f37c10 LibCore: Refactor a version-reading utility
`ArgsParser` and `AboutDialog` had the same procedure to read the
version from `/res/version.ini`. Now they use the `SERENITY_VERSION`
string by default.

This commit refactored the version-reading utility to the new
`Core::Version` namespace.
2021-09-02 16:17:18 +01:00
Mahmoud Mandour
ad80d4dce0 LibCore+LibGUI: Define a Serenity version in LibCore
Before, `AboutDialog` and `ArgsParser` read from a build-time created
file called `/res/version.ini`. This caused problems with utilities
unveiling specific paths leaving the version file unaccessible.

This commit hard-codes a serenity version in `LibCore`, and use it in
`ArgsParser` and `AboutDialog`.

The previous version contained the hash of the last GIT commit, this is
omitted for the default use for the sake of simplicity.
2021-09-02 16:17:18 +01:00
sin-ack
749f62860e LibCore: Remove deferred_invoke overload with Object& parameter
This is not necessary because the user can just use this, which is
referenced until the deferred invocation is complete.
2021-09-02 03:47:47 +04:30
sin-ack
e9121f8b1f LibCore+Userland: Implement Core::deferred_invoke
Core::deferred_invoke is a way of executing an action after previously
queued events have been processed. It removes the requirement of
having/being a Core::Object subclass in order to defer invocation
through Core::Object::deferred_invoke.

Core::Object::deferred_invoke now delegates to Core::deferred_invoke.
The version with the Object& argument is still present but will be
removed in the following commits.

This commit additionally fixes a new places where the
DeferredInvocationEvent was dispatched to the event loop directly, and
replaces them with the Core::deferred_invoke equivalent.
2021-09-02 03:47:47 +04:30
Peter Elliott
33d7fdca28 Everywhere: Use my cool new @serenityos.org email address 2021-09-01 11:37:25 +04:30
Andrew Kaster
d6de0613f5 LibCore: Store ObjectRegistration names as StringViews
We don't need to be allocating Strings for these names during static
initialization. The C-string literals will be stored in the .rodata ELF
section, so they're not going anywhere. We can just wrap the .rodata
storage for the class names in StringViews and use those in Object
registration and lookup APIs.
2021-08-28 23:34:30 +02:00
Andreas Kling
67a0fa2b78 LibCore: Add Core::EventLoop::has_been_instantiated()
This static bool getter can be used to VERIFY that an event loop exists,
in situations where one is expected.

This is helpful if the absence of an event loop would generate strange
and/or loud errors that don't immediately point to this as a cause.
2021-08-26 00:54:27 +02:00
Ralf Donau
a501b903b5 LibCore: Set file offset in ConfigFile::sync 2021-08-24 18:17:09 +02:00
networkException
acde7d12b0 Everywhere: Rename get in ConfigFile::get_for_{lib,app,system} to open
This patch brings the ConfigFile helpers for opening lib, app and system
configs more inline with the regular ConfigFile::open functions.
2021-08-22 01:32:25 +02:00
networkException
54bbe52b51 LibCore: Convert ConfigFile to east const 2021-08-22 01:32:25 +02:00
networkException
2ea2d026c2 LibCore: Support using a file descriptor for opening ConfigFile
This patch adds support for opening a ConfigFile using a file
descriptor rather than trying to open a the file by name directly.

In contrast to the previous implementation, ConfigFile now always keeps
a reference to an open File and does not reopen it for writing.

This requires providing an additional argument to open functions if a
file gets opened based on its name and the user of the api intends to
write to the file in the future.
2021-08-22 01:32:25 +02:00
TheFightingCatfish
9721b7b2dd LibCore: Show version and help before parsing positional arguments
This allows `--version` and `--help` to work properly even if we do not
supply the required positional arguments to a command.
2021-08-20 20:13:12 +02:00
Andreas Kling
13f4890c38 LibCore: Make Core::File::open() return OSError in case of failure 2021-08-20 15:31:46 +02:00
fladd
1de104c6c4 LibCore: Fix build error in File.cpp on macOS
struct stat on macOS doesn't have st_atim.tv_sec and therefore broke the
Lagom build. Replacing it with st_atime fixes that.
2021-08-19 19:47:34 +01:00
Idan Horowitz
95bc8e4641 LibCore: Make DateTime's members signed
Core::DateTime is essentially a C++ wrapper of the tm struct, so we
should support the same signed range as the underlying tm.
2021-08-19 19:15:00 +01:00
Jean-Baptiste Boric
8cc8d72619 LibCore: Implement preserve flag for file/directory copy 2021-08-18 20:30:46 +02:00
Brian Gianforcaro
da51b8f39d LibCore: Move EventLoop to AK::Time 2021-08-15 12:20:38 +02:00
Nico Weber
f25be94487 LibCore: Make --version print same version as in LibGUI's About dialogs
Making every binary's behavior depend on the current git hash seems a
bit questionable to me, but we should be self-consistent about this.
2021-08-15 01:22:45 +02:00
Nico Weber
a45b6dbc07 LibCore: Include math.h instead of defining isnan() in ArgsParser.cpp 2021-08-15 01:22:45 +02:00
Nico Weber
1f71d7bf22 LibCore: Add --version flag to ArgsParser
`--version` always prints "git" for now.

The motivation is that the neofetch port calls `Shell --version` and
adds the output to its output. And if `Shell --version` prints a long
error message about it not knowing the flag, neofetch's output looks a
bit ugly. Per Discord discussion, just add the flag to ArgsParser
instead of only to Shell.
2021-08-14 22:46:34 +04:30
brapru
d456af1cd3 LibCore+LibHTTP: Check the status of the socket after EINPROGRESS
Previously the system would assume the socket was connected after the
file descriptor became writeable. Just because the fd is signaled as
ready for output does not necessarily indicate the socket is connected.
Instead, we should check the status of the socket with SO_ERROR and
handle successes/errors accordingly.
2021-08-13 20:30:19 +04:30
Andreas Kling
c94c15d45c Everywhere: Replace AK::Singleton => Singleton 2021-08-08 00:03:45 +02:00
Andreas Kling
f5c3225286 LibCore: Explicitly declare environ in Process.cpp to unbreak macOS 2021-08-06 01:29:09 +02:00
Andreas Kling
6e65b36973 LibCore: Add Core::Process::spawn()
This is a simple wrapper around posix_spawn() that will help us simplify
a bunch of very verbose posix_spawn() invocations.

This first version only supports the simplest case: executing an
executable without passing arguments or doing anything fancy. More
features can be added to cover more cases. :^)
2021-08-06 01:04:11 +02:00
Brian Gianforcaro
176e1cbca7 LibCore: Remove unused header includes 2021-08-01 08:10:16 +02:00
sin-ack
1e44a0c2d9 LibCore: Support registration of TextWrapping properties
This is basically a named boolean.
2021-07-29 22:33:34 +01:00
Peter Elliott
5d6bf83374 LibCore: Prevent LockFile fd from leaking into child process
Fixes #9059
2021-07-29 07:58:17 +02:00
Peter Elliott
fdcfd2816e LibCore: Add LockFile, a filesystem based mutex
This API wraps flock(2) and also handles the file creation and deletion
when the LockFile goes out of scope.
2021-07-22 23:34:15 +02:00
Tom
a635ff4e60 Everywhere: Make tracking cpu usage independent from system ticks
This switches tracking CPU usage to more accurately measure time in
user and kernel land using either the TSC or another time source.
This will also come in handy when implementing a tickless kernel mode.
2021-07-18 22:08:26 +02:00
Tom
7e77a2ec40 Everywhere: Improve CPU usage calculation
As threads come and go, we can't simply account for how many time
slices the threads at any given point may have been using. We need to
also account for threads that have since disappeared. This means we
also need to track how many time slices we have expired globally.

However, because this doesn't account for context switches outside of
the system timer tick values may still be under-reported. To solve this
we will need to track more accurate time information on each context
switch.

This also fixes top's cpu usage calculation which was still based on
the number of context switches.

Fixes #6473
2021-07-18 22:08:26 +02:00