mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibIPC+LibWeb+LibWebView+Services: Add Transport::create_paired()
Consolidate the repeated socketpair + adopt + configure pattern from 4 call sites into a single Transport::create_paired() factory method. This fixes inconsistent error handling and socket configuration across call sites, and prepares for future mach port support on macOS.
This commit is contained in:
committed by
Alexander Kalenik
parent
d3495c62a7
commit
2e881978af
Notes:
github-actions[bot]
2026-03-11 13:44:16 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/2e881978afe Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8364
@@ -56,22 +56,13 @@ Messages::ImageDecoderServer::InitTransportResponse ConnectionFromClient::init_t
|
||||
|
||||
ErrorOr<IPC::File> ConnectionFromClient::connect_new_client()
|
||||
{
|
||||
int socket_fds[2] {};
|
||||
if (auto err = Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds); err.is_error())
|
||||
return err.release_error();
|
||||
auto paired = TRY(IPC::Transport::create_paired());
|
||||
auto peer_fd = TRY(paired.remote->release_underlying_transport_for_transfer());
|
||||
|
||||
auto client_socket_or_error = Core::LocalSocket::adopt_fd(socket_fds[0]);
|
||||
if (client_socket_or_error.is_error()) {
|
||||
(void)Core::System::close(socket_fds[0]);
|
||||
(void)Core::System::close(socket_fds[1]);
|
||||
return client_socket_or_error.release_error();
|
||||
}
|
||||
|
||||
auto client_socket = client_socket_or_error.release_value();
|
||||
// Note: A ref is stored in the static s_connections map
|
||||
auto client = adopt_ref(*new ConnectionFromClient(make<IPC::Transport>(move(client_socket))));
|
||||
auto client = adopt_ref(*new ConnectionFromClient(move(paired.local)));
|
||||
|
||||
return IPC::File::adopt_fd(socket_fds[1]);
|
||||
return IPC::File::adopt_fd(peer_fd);
|
||||
}
|
||||
|
||||
Messages::ImageDecoderServer::ConnectNewClientsResponse ConnectionFromClient::connect_new_clients(size_t count)
|
||||
|
||||
@@ -139,22 +139,13 @@ Messages::RequestServer::ConnectNewClientsResponse ConnectionFromClient::connect
|
||||
|
||||
ErrorOr<IPC::File> ConnectionFromClient::create_client_socket()
|
||||
{
|
||||
// TODO: Mach IPC
|
||||
|
||||
int socket_fds[2] {};
|
||||
TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds));
|
||||
|
||||
auto client_socket = Core::LocalSocket::adopt_fd(socket_fds[0]);
|
||||
if (client_socket.is_error()) {
|
||||
close(socket_fds[0]);
|
||||
close(socket_fds[1]);
|
||||
return client_socket.release_error();
|
||||
}
|
||||
auto paired = TRY(IPC::Transport::create_paired());
|
||||
auto peer_fd = TRY(paired.remote->release_underlying_transport_for_transfer());
|
||||
|
||||
// Note: A ref is stored in the m_connections map
|
||||
auto client = adopt_ref(*new ConnectionFromClient(make<IPC::Transport>(client_socket.release_value()), IsPrimaryConnection::No, m_connections, m_disk_cache));
|
||||
auto client = adopt_ref(*new ConnectionFromClient(move(paired.local), IsPrimaryConnection::No, m_connections, m_disk_cache));
|
||||
|
||||
return IPC::File::adopt_fd(socket_fds[1]);
|
||||
return IPC::File::adopt_fd(peer_fd);
|
||||
}
|
||||
|
||||
void ConnectionFromClient::set_disk_cache_settings(HTTP::DiskCacheSettings disk_cache_settings)
|
||||
|
||||
Reference in New Issue
Block a user