1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:47:36 +00:00

LibCore: Convert CTCPSocket to ObjectPtr, add construct() helper

The C_OBJECT macro now also inserts a static construct(...) helper into
the class. Now we can make the constructor(s) private and instead call:

    auto socket = CTCPSocket::construct(arguments);

construct() returns an ObjectPtr<T>, which we'll later switch to being
a NonnullRefPtr<T>, once everything else in in place for ref-counting.
This commit is contained in:
Andreas Kling 2019-09-21 10:13:34 +02:00
parent 1f5a9762a2
commit 4298ba25c3
15 changed files with 30 additions and 25 deletions

View file

@ -10,9 +10,9 @@
#include "Client.h"
Client::Client(int id, CTCPSocket* socket, int ptm_fd)
Client::Client(int id, ObjectPtr<CTCPSocket> socket, int ptm_fd)
: m_id(id)
, m_socket(socket)
, m_socket(move(socket))
, m_ptm_fd(ptm_fd)
, m_ptm_notifier(CNotifier::create(ptm_fd, CNotifier::Read))
{

View file

@ -11,15 +11,15 @@
class Client : public RefCounted<Client> {
public:
static NonnullRefPtr<Client> create(int id, CTCPSocket* socket, int ptm_fd)
static NonnullRefPtr<Client> create(int id, ObjectPtr<CTCPSocket> socket, int ptm_fd)
{
return adopt(*new Client(id, socket, ptm_fd));
return adopt(*new Client(id, move(socket), ptm_fd));
}
Function<void()> on_exit;
protected:
Client(int id, CTCPSocket* socket, int ptm_fd);
Client(int id, ObjectPtr<CTCPSocket> socket, int ptm_fd);
void drain_socket();
void drain_pty();
@ -35,7 +35,7 @@ private:
// client id
int m_id { 0 };
// client resources
CTCPSocket* m_socket { nullptr };
ObjectPtr<CTCPSocket> m_socket;
Parser m_parser;
// pty resources
int m_ptm_fd { -1 };

View file

@ -107,7 +107,7 @@ int main(int argc, char** argv)
server.on_ready_to_accept = [&next_id, &clients, &server] {
int id = next_id++;
auto* client_socket = server.accept();
auto client_socket = server.accept();
if (!client_socket) {
perror("accept");
return;