mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
Rename new IPC headers & classes
Sticking these in a namespace allows us to use a more generic ("Connection") term without clashing, which is way easier to understand than to try to come up with unique names for both.
This commit is contained in:
parent
2177594c96
commit
9c8dd836fc
Notes:
sideshowbarker
2024-07-19 13:12:17 +09:00
Author: https://github.com/rburchell Commit: https://github.com/SerenityOS/serenity/commit/9c8dd836fc0 Pull-request: https://github.com/SerenityOS/serenity/pull/327 Reviewed-by: https://github.com/awesomekling
12 changed files with 71 additions and 59 deletions
|
@ -3,7 +3,7 @@
|
|||
#include "AClientConnection.h"
|
||||
|
||||
AClientConnection::AClientConnection()
|
||||
: CIPCClientSideConnection("/tmp/asportal")
|
||||
: Connection("/tmp/asportal")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
#include <LibCore/CLocalSocket.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibCore/CIPCClientSideConnection.h>
|
||||
#include <LibCore/CoreIPCClient.h>
|
||||
#include <LibAudio/ASAPI.h>
|
||||
|
||||
class ABuffer;
|
||||
|
||||
class AClientConnection : public CIPCClientSideConnection<ASAPI_ServerMessage, ASAPI_ClientMessage> {
|
||||
class AClientConnection : public IPC::Client::Connection<ASAPI_ServerMessage, ASAPI_ClientMessage> {
|
||||
public:
|
||||
AClientConnection();
|
||||
|
||||
|
|
|
@ -15,23 +15,27 @@
|
|||
|
||||
//#define CIPC_DEBUG
|
||||
|
||||
class CIPCClientEvent : public CEvent {
|
||||
namespace IPC
|
||||
{
|
||||
namespace Client {
|
||||
|
||||
class Event : public CEvent {
|
||||
public:
|
||||
enum Type {
|
||||
Invalid = 2000,
|
||||
DoPostprocess,
|
||||
PostProcess,
|
||||
};
|
||||
CIPCClientEvent() {}
|
||||
explicit CIPCClientEvent(Type type)
|
||||
Event() {}
|
||||
explicit Event(Type type)
|
||||
: CEvent(type)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class CIPCClientPostprocessEvent : public CIPCClientEvent {
|
||||
class PostProcessEvent : public Event {
|
||||
public:
|
||||
explicit CIPCClientPostprocessEvent(int client_id)
|
||||
: CIPCClientEvent(DoPostprocess)
|
||||
explicit PostProcessEvent(int client_id)
|
||||
: Event(PostProcess)
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
}
|
||||
|
@ -43,16 +47,16 @@ private:
|
|||
};
|
||||
|
||||
template <typename ServerMessage, typename ClientMessage>
|
||||
class CIPCClientSideConnection : public CObject {
|
||||
class Connection : public CObject {
|
||||
public:
|
||||
CIPCClientSideConnection(const StringView& address)
|
||||
Connection(const StringView& address)
|
||||
: m_notifier(CNotifier(m_connection.fd(), CNotifier::Read))
|
||||
{
|
||||
// We want to rate-limit our clients
|
||||
m_connection.set_blocking(true);
|
||||
m_notifier.on_ready_to_read = [this] {
|
||||
drain_messages_from_server();
|
||||
CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd()));
|
||||
CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd()));
|
||||
};
|
||||
|
||||
int retries = 1000;
|
||||
|
@ -61,7 +65,7 @@ public:
|
|||
break;
|
||||
}
|
||||
|
||||
dbgprintf("CIPCClientSideConnection: connect failed: %d, %s\n", errno, strerror(errno));
|
||||
dbgprintf("Client::Connection: connect failed: %d, %s\n", errno, strerror(errno));
|
||||
sleep(1);
|
||||
--retries;
|
||||
}
|
||||
|
@ -73,7 +77,7 @@ public:
|
|||
|
||||
virtual void event(CEvent& event) override
|
||||
{
|
||||
if (event.type() == CIPCClientEvent::DoPostprocess) {
|
||||
if (event.type() == Event::PostProcess) {
|
||||
postprocess_bundles(m_unprocessed_bundles);
|
||||
} else {
|
||||
CObject::event(event);
|
||||
|
@ -94,7 +98,7 @@ public:
|
|||
if (m_unprocessed_bundles[i].message.type == type) {
|
||||
event = move(m_unprocessed_bundles[i].message);
|
||||
m_unprocessed_bundles.remove(i);
|
||||
CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd()));
|
||||
CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +119,7 @@ public:
|
|||
if (m_unprocessed_bundles[i].message.type == type) {
|
||||
event = move(m_unprocessed_bundles[i].message);
|
||||
m_unprocessed_bundles.remove(i);
|
||||
CEventLoop::current().post_event(*this, make<CIPCClientPostprocessEvent>(m_connection.fd()));
|
||||
CEventLoop::current().post_event(*this, make<PostProcessEvent>(m_connection.fd()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -164,14 +168,14 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
struct IncomingASMessageBundle {
|
||||
struct IncomingMessageBundle {
|
||||
ServerMessage message;
|
||||
ByteBuffer extra_data;
|
||||
};
|
||||
|
||||
virtual void postprocess_bundles(Vector<IncomingASMessageBundle>& new_bundles)
|
||||
virtual void postprocess_bundles(Vector<IncomingMessageBundle>& new_bundles)
|
||||
{
|
||||
dbg() << "CIPCClientSideConnection " << " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want";
|
||||
dbg() << "Client::Connection: " << " warning: discarding " << new_bundles.size() << " unprocessed bundles; this may not be what you want";
|
||||
new_bundles.clear();
|
||||
}
|
||||
|
||||
|
@ -214,7 +218,11 @@ private:
|
|||
|
||||
CLocalSocket m_connection;
|
||||
CNotifier m_notifier;
|
||||
Vector<IncomingASMessageBundle> m_unprocessed_bundles;
|
||||
Vector<IncomingMessageBundle> m_unprocessed_bundles;
|
||||
int m_server_pid;
|
||||
int m_my_client_id;
|
||||
};
|
||||
|
||||
} // Client
|
||||
} // IPC
|
||||
|
|
@ -15,23 +15,27 @@
|
|||
|
||||
//#define CIPC_DEBUG
|
||||
|
||||
class CIPCServerEvent : public CEvent {
|
||||
namespace IPC
|
||||
{
|
||||
namespace Server {
|
||||
|
||||
class Event : public CEvent {
|
||||
public:
|
||||
enum Type {
|
||||
Invalid = 2000,
|
||||
ClientDisconnected,
|
||||
Disconnected,
|
||||
};
|
||||
CIPCServerEvent() {}
|
||||
explicit CIPCServerEvent(Type type)
|
||||
Event() {}
|
||||
explicit Event(Type type)
|
||||
: CEvent(type)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class ASClientDisconnectedNotification : public CIPCServerEvent {
|
||||
class DisconnectedEvent : public Event {
|
||||
public:
|
||||
explicit ASClientDisconnectedNotification(int client_id)
|
||||
: CIPCServerEvent(ClientDisconnected)
|
||||
explicit DisconnectedEvent(int client_id)
|
||||
: Event(Disconnected)
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
}
|
||||
|
@ -43,7 +47,7 @@ private:
|
|||
};
|
||||
|
||||
template <typename T, class... Args>
|
||||
T* CIPCServerSideClientCreator(Args&& ... args)
|
||||
T* new_connection_for_client(Args&& ... args)
|
||||
{
|
||||
auto conn = new T(AK::forward<Args>(args)...) /* arghs */;
|
||||
conn->send_greeting();
|
||||
|
@ -51,24 +55,24 @@ T* CIPCServerSideClientCreator(Args&& ... args)
|
|||
};
|
||||
|
||||
template <typename ServerMessage, typename ClientMessage>
|
||||
class CIPCServerSideClient : public CObject
|
||||
class Connection : public CObject
|
||||
{
|
||||
public:
|
||||
CIPCServerSideClient(int fd, int client_id)
|
||||
Connection(int fd, int client_id)
|
||||
: m_socket(fd)
|
||||
, m_notifier(CNotifier(fd, CNotifier::Read))
|
||||
, m_client_id(client_id)
|
||||
{
|
||||
m_notifier.on_ready_to_read = [this] { drain_client(); };
|
||||
#if defined(CIPC_DEBUG)
|
||||
dbg() << "S: Created new CIPCServerSideClient " << fd << client_id << " and said hello";
|
||||
dbg() << "S: Created new Connection " << fd << client_id << " and said hello";
|
||||
#endif
|
||||
}
|
||||
|
||||
~CIPCServerSideClient()
|
||||
~Connection()
|
||||
{
|
||||
#if defined(CIPC_DEBUG)
|
||||
dbg() << "S: Destroyed CIPCServerSideClient " << m_socket.fd() << client_id();
|
||||
dbg() << "S: Destroyed Connection " << m_socket.fd() << client_id();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -96,17 +100,17 @@ public:
|
|||
if (nwritten < 0) {
|
||||
switch (errno) {
|
||||
case EPIPE:
|
||||
dbgprintf("WSClientConnection::post_message: Disconnected from peer.\n");
|
||||
dbgprintf("Connection::post_message: Disconnected from peer.\n");
|
||||
delete_later();
|
||||
return;
|
||||
break;
|
||||
case EAGAIN:
|
||||
dbgprintf("WSClientConnection::post_message: Client buffer overflowed.\n");
|
||||
dbgprintf("Connection::post_message: Client buffer overflowed.\n");
|
||||
did_misbehave();
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
perror("WSClientConnection::post_message writev");
|
||||
perror("Connection::post_message writev");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +128,7 @@ public:
|
|||
if (nread == 0 || (nread == -1 && errno == EAGAIN)) {
|
||||
if (!messages_received) {
|
||||
// TODO: is delete_later() sufficient?
|
||||
CEventLoop::current().post_event(*this, make<ASClientDisconnectedNotification>(client_id()));
|
||||
CEventLoop::current().post_event(*this, make<DisconnectedEvent>(client_id()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -159,12 +163,12 @@ public:
|
|||
|
||||
void did_misbehave()
|
||||
{
|
||||
dbgprintf("CIPCServerSideClient{%p} (id=%d, pid=%d) misbehaved, disconnecting.\n", this, client_id(), m_pid);
|
||||
dbgprintf("Connection{%p} (id=%d, pid=%d) misbehaved, disconnecting.\n", this, client_id(), m_pid);
|
||||
delete_later();
|
||||
m_notifier.set_enabled(false);
|
||||
}
|
||||
|
||||
const char* class_name() const override { return "CIPCServerSideClient"; }
|
||||
const char* class_name() const override { return "Connection"; }
|
||||
|
||||
int client_id() const { return m_client_id; }
|
||||
pid_t client_pid() const { return m_pid; }
|
||||
|
@ -176,9 +180,9 @@ public:
|
|||
protected:
|
||||
void event(CEvent& event)
|
||||
{
|
||||
if (event.type() == CIPCServerEvent::ClientDisconnected) {
|
||||
int client_id = static_cast<const ASClientDisconnectedNotification&>(event).client_id();
|
||||
dbgprintf("CIPCServerSideClient: Client disconnected: %d\n", client_id);
|
||||
if (event.type() == Event::Disconnected) {
|
||||
int client_id = static_cast<const DisconnectedEvent&>(event).client_id();
|
||||
dbgprintf("Connection: Client disconnected: %d\n", client_id);
|
||||
delete this;
|
||||
return;
|
||||
}
|
||||
|
@ -215,4 +219,6 @@ private:
|
|||
int m_pid;
|
||||
};
|
||||
|
||||
} // Server
|
||||
} // IPC
|
||||
|
|
@ -188,7 +188,7 @@ void GWindowServerConnection::handle_wm_event(const WSAPI_ServerMessage& event,
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void GWindowServerConnection::postprocess_bundles(Vector<CIPCClientSideConnection::IncomingASMessageBundle>& bundles)
|
||||
void GWindowServerConnection::postprocess_bundles(Vector<IncomingMessageBundle>& bundles)
|
||||
{
|
||||
int coalesced_paints = 0;
|
||||
int coalesced_resizes = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/CEventLoop.h>
|
||||
#include <LibCore/CIPCClientSideConnection.h>
|
||||
#include <LibCore/CoreIPCClient.h>
|
||||
#include <LibGUI/GEvent.h>
|
||||
#include <WindowServer/WSAPITypes.h>
|
||||
|
||||
|
@ -10,16 +10,16 @@ class CObject;
|
|||
class CNotifier;
|
||||
class GWindow;
|
||||
|
||||
class GWindowServerConnection : public CIPCClientSideConnection<WSAPI_ServerMessage, WSAPI_ClientMessage> {
|
||||
class GWindowServerConnection : public IPC::Client::Connection<WSAPI_ServerMessage, WSAPI_ClientMessage> {
|
||||
public:
|
||||
GWindowServerConnection()
|
||||
: CIPCClientSideConnection("/tmp/wsportal")
|
||||
: Connection("/tmp/wsportal")
|
||||
{}
|
||||
|
||||
void handshake() override;
|
||||
|
||||
private:
|
||||
void postprocess_bundles(Vector<IncomingASMessageBundle>& m_unprocessed_bundles) override;
|
||||
void postprocess_bundles(Vector<IncomingMessageBundle>& m_unprocessed_bundles) override;
|
||||
void handle_paint_event(const WSAPI_ServerMessage&, GWindow&, const ByteBuffer& extra_data);
|
||||
void handle_resize_event(const WSAPI_ServerMessage&, GWindow&);
|
||||
void handle_mouse_event(const WSAPI_ServerMessage&, GWindow&);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
ASClientConnection::ASClientConnection(int fd, int client_id, ASMixer& mixer)
|
||||
: CIPCServerSideClient(fd, client_id)
|
||||
: Connection(fd, client_id)
|
||||
, m_mixer(mixer)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/CIPCServerSideClient.h>
|
||||
#include <LibCore/CoreIPCServer.h>
|
||||
#include <LibAudio/ASAPI.h>
|
||||
|
||||
class ASMixer;
|
||||
|
||||
class ASClientConnection final : public CIPCServerSideClient<ASAPI_ServerMessage, ASAPI_ClientMessage>
|
||||
class ASClientConnection final : public IPC::Server::Connection<ASAPI_ServerMessage, ASAPI_ClientMessage>
|
||||
{
|
||||
public:
|
||||
explicit ASClientConnection(int fd, int client_id, ASMixer& mixer);
|
||||
|
|
|
@ -31,8 +31,7 @@ void ASEventLoop::drain_server()
|
|||
} else {
|
||||
dbgprintf("AudioServer: accept()ed client %d\n", client_fd);
|
||||
static int s_next_client_id = 0;
|
||||
CIPCServerSideClientCreator<ASClientConnection>(client_fd, s_next_client_id++, m_mixer);
|
||||
//new ASClientConnection(client_fd, s_next_client_id++, m_mixer);
|
||||
IPC::Server::new_connection_for_client<ASClientConnection>(client_fd, s_next_client_id++, m_mixer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ WSClientConnection* WSClientConnection::from_client_id(int client_id)
|
|||
}
|
||||
|
||||
WSClientConnection::WSClientConnection(int fd, int client_id)
|
||||
: CIPCServerSideClient(fd, client_id)
|
||||
: Connection(fd, client_id)
|
||||
{
|
||||
if (!s_connections)
|
||||
s_connections = new HashMap<int, WSClientConnection*>;
|
||||
|
@ -88,7 +88,7 @@ void WSClientConnection::event(CEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
CIPCServerSideClient::event(event);
|
||||
Connection::event(event);
|
||||
}
|
||||
|
||||
static Vector<Rect, 32> get_rects(const WSAPI_ClientMessage& message, const ByteBuffer& extra_data)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <AK/OwnPtr.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/CObject.h>
|
||||
#include <LibCore/CIPCServerSideClient.h>
|
||||
#include <LibCore/CoreIPCServer.h>
|
||||
#include <SharedGraphics/GraphicsBitmap.h>
|
||||
#include <WindowServer/WSEvent.h>
|
||||
|
||||
|
@ -13,7 +13,7 @@ class WSWindow;
|
|||
class WSMenu;
|
||||
class WSMenuBar;
|
||||
|
||||
class WSClientConnection final : public CIPCServerSideClient<WSAPI_ServerMessage, WSAPI_ClientMessage> {
|
||||
class WSClientConnection final : public IPC::Server::Connection<WSAPI_ServerMessage, WSAPI_ClientMessage> {
|
||||
public:
|
||||
explicit WSClientConnection(int fd, int client_id);
|
||||
~WSClientConnection() override;
|
||||
|
|
|
@ -62,8 +62,7 @@ void WSEventLoop::drain_server()
|
|||
} else {
|
||||
static int s_next_client_id = 0;
|
||||
int client_id = ++s_next_client_id;
|
||||
|
||||
CIPCServerSideClientCreator<WSClientConnection>(client_fd, client_id);
|
||||
IPC::Server::new_connection_for_client<WSClientConnection>(client_fd, client_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue