mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibSQL: Support launching a singleton SQLServer instance for Lagom hosts
On Serenity, SQLServer is started by SystemServer. But on Lagom, it is manually started by e.g. Ladybird when the application is started, and killed when the application exits. This means every Ladybird process starts its own SQLServer, which defeats the purpose of SQLServer acting as the single process interacting with the database files. This patch will allow SQLClient to start up a single SQLServer instance, first checking if one already exists. If it does exist, SQLClient will simply connect to SQLServer's socket. If it does not exist, SQLClient will launch SQLServer much like SystemServer would (with a local socket file, etc.). The child SQLServer process is double-forked; the grandchild process becomes the SQLServer process, which the middle child process simply exits to "detach" the grandchild process from the SQLClient process.
This commit is contained in:
parent
12152a4556
commit
4e5f56f737
2 changed files with 142 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Platform.h>
|
||||
#include <LibIPC/ConnectionToServer.h>
|
||||
#include <LibSQL/Result.h>
|
||||
#include <SQLServer/SQLClientEndpoint.h>
|
||||
|
@ -20,10 +21,9 @@ class SQLClient
|
|||
IPC_CLIENT_CONNECTION(SQLClient, "/tmp/session/%sid/portal/sql"sv)
|
||||
|
||||
public:
|
||||
explicit SQLClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||
: IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>(*this, move(socket))
|
||||
{
|
||||
}
|
||||
#if !defined(AK_OS_SERENITY)
|
||||
static ErrorOr<NonnullRefPtr<SQLClient>> launch_server_and_create_client(StringView server_path);
|
||||
#endif
|
||||
|
||||
virtual ~SQLClient() = default;
|
||||
|
||||
|
@ -33,6 +33,11 @@ public:
|
|||
Function<void(u64, u64, size_t)> on_results_exhausted;
|
||||
|
||||
private:
|
||||
explicit SQLClient(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
||||
: IPC::ConnectionToServer<SQLClientEndpoint, SQLServerEndpoint>(*this, move(socket))
|
||||
{
|
||||
}
|
||||
|
||||
virtual void execution_success(u64 statement_id, u64 execution_id, bool has_results, size_t created, size_t updated, size_t deleted) override;
|
||||
virtual void next_result(u64 statement_id, u64 execution_id, Vector<SQL::Value> const&) override;
|
||||
virtual void results_exhausted(u64 statement_id, u64 execution_id, size_t total_rows) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue