mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-30 21:28:59 +00:00
LibCore: Support launching a singleton process with an IPC connection
This largely adapts the code from SingletonProcess.cpp to work a bit closer with Core::Process. Ideally, we'll move the daemonizing feature into Core::Process::disown() eventually.
This commit is contained in:
parent
8448897f14
commit
c723fc9611
Notes:
sideshowbarker
2024-07-17 09:47:09 +09:00
Author: https://github.com/trflynn89
Commit: c723fc9611
Pull-request: https://github.com/SerenityOS/serenity/pull/24092
Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 148 additions and 0 deletions
|
@ -44,6 +44,8 @@ struct ProcessSpawnOptions {
|
|||
Vector<FileActionType> const& file_actions {};
|
||||
};
|
||||
|
||||
class IPCProcess;
|
||||
|
||||
class Process {
|
||||
AK_MAKE_NONCOPYABLE(Process);
|
||||
|
||||
|
@ -98,6 +100,8 @@ public:
|
|||
ErrorOr<bool> wait_for_termination();
|
||||
|
||||
private:
|
||||
friend IPCProcess;
|
||||
|
||||
Process(pid_t pid)
|
||||
: m_pid(pid)
|
||||
, m_should_disown(true)
|
||||
|
@ -125,6 +129,15 @@ public:
|
|||
return ProcessAndIPCClient<ClientType> { move(process), move(client) };
|
||||
}
|
||||
|
||||
template<typename ClientType, typename... ClientArguments>
|
||||
static ErrorOr<ProcessAndIPCClient<ClientType>> spawn_singleton(ProcessSpawnOptions const& options, ClientArguments&&... client_arguments)
|
||||
{
|
||||
auto [process, socket] = TRY(spawn_singleton_and_connect_to_process(options));
|
||||
auto client = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ClientType { move(socket), forward<ClientArguments>(client_arguments)... }));
|
||||
|
||||
return ProcessAndIPCClient<ClientType> { move(process), move(client) };
|
||||
}
|
||||
|
||||
pid_t pid() const { return m_process.pid(); }
|
||||
|
||||
private:
|
||||
|
@ -133,6 +146,7 @@ private:
|
|||
NonnullOwnPtr<Core::LocalSocket> m_ipc_socket;
|
||||
};
|
||||
static ErrorOr<ProcessAndIPCSocket> spawn_and_connect_to_process(ProcessSpawnOptions const& options);
|
||||
static ErrorOr<ProcessAndIPCSocket> spawn_singleton_and_connect_to_process(ProcessSpawnOptions const& options);
|
||||
|
||||
Process m_process;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue