mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
LibIPC+Services: Make ClientConnection take socket as NonnullRefPtr
This avoids getting into the awkward situation where the socket is still part-owned by main() in multi-instance service. Also it just reads nicer.
This commit is contained in:
parent
f9d3055691
commit
94ddb07e58
25 changed files with 40 additions and 40 deletions
|
@ -48,7 +48,7 @@ public:
|
|||
Invalid = 2000,
|
||||
Disconnected,
|
||||
};
|
||||
Event() {}
|
||||
Event() { }
|
||||
explicit Event(Type type)
|
||||
: Core::Event(type)
|
||||
{
|
||||
|
@ -78,19 +78,18 @@ NonnullRefPtr<T> new_client_connection(Args&&... args)
|
|||
template<typename Endpoint>
|
||||
class ClientConnection : public Core::Object {
|
||||
public:
|
||||
ClientConnection(Endpoint& endpoint, Core::LocalSocket& socket, int client_id)
|
||||
ClientConnection(Endpoint& endpoint, NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: m_endpoint(endpoint)
|
||||
, m_socket(socket)
|
||||
, m_socket(move(socket))
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
ASSERT(socket.is_connected());
|
||||
ASSERT(m_socket->is_connected());
|
||||
ucred creds;
|
||||
socklen_t creds_size = sizeof(creds);
|
||||
if (getsockopt(m_socket->fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
m_client_pid = creds.pid;
|
||||
add_child(socket);
|
||||
m_socket->on_ready_to_read = [this] { drain_messages_from_client(); };
|
||||
|
||||
m_responsiveness_timer = Core::Timer::create_single_shot(3000, [this] { may_have_become_unresponsive(); });
|
||||
|
@ -100,8 +99,8 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
virtual void may_have_become_unresponsive() {}
|
||||
virtual void did_become_responsive() {}
|
||||
virtual void may_have_become_unresponsive() { }
|
||||
virtual void did_become_responsive() { }
|
||||
|
||||
void post_message(const Message& message)
|
||||
{
|
||||
|
@ -223,7 +222,7 @@ protected:
|
|||
|
||||
private:
|
||||
Endpoint& m_endpoint;
|
||||
RefPtr<Core::LocalSocket> m_socket;
|
||||
NonnullRefPtr<Core::LocalSocket> m_socket;
|
||||
RefPtr<Core::Timer> m_responsiveness_timer;
|
||||
int m_client_id { -1 };
|
||||
int m_client_pid { -1 };
|
||||
|
|
|
@ -50,8 +50,8 @@ void ClientConnection::for_each(Function<void(ClientConnection&)> callback)
|
|||
callback(connection);
|
||||
}
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id, Mixer& mixer)
|
||||
: IPC::ClientConnection<AudioServerEndpoint>(*this, client_socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id, Mixer& mixer)
|
||||
: IPC::ClientConnection<AudioServerEndpoint>(*this, move(client_socket), client_id)
|
||||
, m_mixer(mixer)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
|
|
|
@ -43,7 +43,7 @@ class ClientConnection final : public IPC::ClientConnection<AudioServerEndpoint>
|
|||
, public AudioServerEndpoint {
|
||||
C_OBJECT(ClientConnection)
|
||||
public:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id, Mixer& mixer);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id, Mixer& mixer);
|
||||
~ClientConnection() override;
|
||||
|
||||
void did_finish_playing_buffer(Badge<BufferQueue>, int buffer_id);
|
||||
|
|
|
@ -49,7 +49,7 @@ int main(int, char**)
|
|||
}
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
IPC::new_client_connection<AudioServer::ClientConnection>(*client_socket, client_id, mixer);
|
||||
IPC::new_client_connection<AudioServer::ClientConnection>(client_socket.release_nonnull(), client_id, mixer);
|
||||
};
|
||||
|
||||
if (pledge("stdio thread shared_buffer accept", nullptr) < 0) {
|
||||
|
|
|
@ -41,8 +41,8 @@ void ClientConnection::for_each_client(Function<void(ClientConnection&)> callbac
|
|||
}
|
||||
}
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& socket, int client_id)
|
||||
: IPC::ClientConnection<ClipboardServerEndpoint>(*this, socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::ClientConnection<ClipboardServerEndpoint>(*this, move(socket), client_id)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class ClientConnection final : public IPC::ClientConnection<ClipboardServerEndpo
|
|||
C_OBJECT(ClientConnection);
|
||||
|
||||
public:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
virtual ~ClientConnection() override;
|
||||
|
||||
virtual void die() override;
|
||||
|
|
|
@ -63,7 +63,7 @@ int main(int, char**)
|
|||
}
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
IPC::new_client_connection<Clipboard::ClientConnection>(*client_socket, client_id);
|
||||
IPC::new_client_connection<Clipboard::ClientConnection>(client_socket.release_nonnull(), client_id);
|
||||
};
|
||||
|
||||
Clipboard::Storage::the().on_content_change = [&] {
|
||||
|
|
|
@ -9,4 +9,4 @@ set(SOURCES
|
|||
)
|
||||
|
||||
serenity_bin(ImageDecoder)
|
||||
target_link_libraries(ImageDecoder LibIPC LibGfx)
|
||||
target_link_libraries(ImageDecoder LibGfx LibIPC)
|
||||
|
|
|
@ -36,8 +36,8 @@ namespace ImageDecoder {
|
|||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& socket, int client_id)
|
||||
: IPC::ClientConnection<ImageDecoderServerEndpoint>(*this, socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::ClientConnection<ImageDecoderServerEndpoint>(*this, move(socket), client_id)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ class ClientConnection final
|
|||
C_OBJECT(ClientConnection);
|
||||
|
||||
public:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
~ClientConnection() override;
|
||||
|
||||
virtual void die() override;
|
||||
|
|
|
@ -42,7 +42,7 @@ int main(int, char**)
|
|||
}
|
||||
|
||||
auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
|
||||
IPC::new_client_connection<ImageDecoder::ClientConnection>(*socket, 1);
|
||||
IPC::new_client_connection<ImageDecoder::ClientConnection>(socket.release_nonnull(), 1);
|
||||
if (pledge("stdio shared_buffer", nullptr) < 0) {
|
||||
perror("pledge");
|
||||
return 1;
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
namespace LaunchServer {
|
||||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id)
|
||||
: IPC::ClientConnection<LaunchServerEndpoint>(*this, client_socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
|
||||
: IPC::ClientConnection<LaunchServerEndpoint>(*this, move(client_socket), client_id)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual void die() override;
|
||||
|
||||
private:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
|
||||
virtual OwnPtr<Messages::LaunchServer::GreetResponse> handle(const Messages::LaunchServer::Greet&) override;
|
||||
virtual OwnPtr<Messages::LaunchServer::OpenURLResponse> handle(const Messages::LaunchServer::OpenURL&) override;
|
||||
|
|
|
@ -61,7 +61,7 @@ int main(int argc, char** argv)
|
|||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
dbg() << "Received connection";
|
||||
IPC::new_client_connection<LaunchServer::ClientConnection>(*client_socket, client_id);
|
||||
IPC::new_client_connection<LaunchServer::ClientConnection>(client_socket.release_nonnull(), client_id);
|
||||
};
|
||||
|
||||
return event_loop.exec();
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace NotificationServer {
|
|||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id)
|
||||
: IPC::ClientConnection<NotificationServerEndpoint>(*this, client_socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
|
||||
: IPC::ClientConnection<NotificationServerEndpoint>(*this, move(client_socket), client_id)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual void die() override;
|
||||
|
||||
private:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
|
||||
virtual OwnPtr<Messages::NotificationServer::GreetResponse> handle(const Messages::NotificationServer::Greet&) override;
|
||||
virtual OwnPtr<Messages::NotificationServer::ShowNotificationResponse> handle(const Messages::NotificationServer::ShowNotification&) override;
|
||||
|
|
|
@ -52,7 +52,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
IPC::new_client_connection<NotificationServer::ClientConnection>(*client_socket, client_id);
|
||||
IPC::new_client_connection<NotificationServer::ClientConnection>(client_socket.release_nonnull(), client_id);
|
||||
};
|
||||
|
||||
if (unveil("/res", "r") < 0) {
|
||||
|
|
|
@ -35,8 +35,8 @@ namespace ProtocolServer {
|
|||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& socket, int client_id)
|
||||
: IPC::ClientConnection<ProtocolServerEndpoint>(*this, socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::ClientConnection<ProtocolServerEndpoint>(*this, move(socket), client_id)
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class ClientConnection final
|
|||
C_OBJECT(ClientConnection);
|
||||
|
||||
public:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
~ClientConnection() override;
|
||||
|
||||
virtual void die() override;
|
||||
|
|
|
@ -36,8 +36,8 @@ namespace WebContent {
|
|||
|
||||
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& socket, int client_id)
|
||||
: IPC::ClientConnection<WebContentServerEndpoint>(*this, socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> socket, int client_id)
|
||||
: IPC::ClientConnection<WebContentServerEndpoint>(*this, move(socket), client_id)
|
||||
, m_page_host(PageHost::create(*this))
|
||||
{
|
||||
s_connections.set(client_id, *this);
|
||||
|
|
|
@ -40,7 +40,7 @@ class ClientConnection final
|
|||
C_OBJECT(ClientConnection);
|
||||
|
||||
public:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
~ClientConnection() override;
|
||||
|
||||
virtual void die() override;
|
||||
|
|
|
@ -54,6 +54,7 @@ int main(int, char**)
|
|||
}
|
||||
|
||||
auto socket = Core::LocalSocket::take_over_accepted_socket_from_system_server();
|
||||
IPC::new_client_connection<WebContent::ClientConnection>(*socket, 1);
|
||||
ASSERT(socket);
|
||||
IPC::new_client_connection<WebContent::ClientConnection>(socket.release_nonnull(), 1);
|
||||
return event_loop.exec();
|
||||
}
|
||||
|
|
|
@ -77,8 +77,8 @@ ClientConnection* ClientConnection::from_client_id(int client_id)
|
|||
return (*it).value.ptr();
|
||||
}
|
||||
|
||||
ClientConnection::ClientConnection(Core::LocalSocket& client_socket, int client_id)
|
||||
: IPC::ClientConnection<WindowServerEndpoint>(*this, client_socket, client_id)
|
||||
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
|
||||
: IPC::ClientConnection<WindowServerEndpoint>(*this, move(client_socket), client_id)
|
||||
{
|
||||
if (!s_connections)
|
||||
s_connections = new HashMap<int, NonnullRefPtr<ClientConnection>>;
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
void notify_display_link(Badge<Compositor>);
|
||||
|
||||
private:
|
||||
explicit ClientConnection(Core::LocalSocket&, int client_id);
|
||||
explicit ClientConnection(NonnullRefPtr<Core::LocalSocket>, int client_id);
|
||||
|
||||
// ^ClientConnection
|
||||
virtual void die() override;
|
||||
|
|
|
@ -63,7 +63,7 @@ EventLoop::EventLoop()
|
|||
}
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
IPC::new_client_connection<ClientConnection>(*client_socket, client_id);
|
||||
IPC::new_client_connection<ClientConnection>(client_socket.release_nonnull(), client_id);
|
||||
};
|
||||
|
||||
ASSERT(m_keyboard_fd >= 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue