diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 10:13:34 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-21 15:25:08 +0200 |
commit | 4298ba25c3b9909781cebc4719af82056591572b (patch) | |
tree | 3db1fec1e15388d8cd60054bff990e9ffef8fbfc /Servers/TelnetServer | |
parent | 1f5a9762a2b9e3449be7e61327c100d2e1f3e9db (diff) | |
download | serenity-4298ba25c3b9909781cebc4719af82056591572b.zip |
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.
Diffstat (limited to 'Servers/TelnetServer')
-rw-r--r-- | Servers/TelnetServer/Client.cpp | 4 | ||||
-rw-r--r-- | Servers/TelnetServer/Client.h | 8 | ||||
-rw-r--r-- | Servers/TelnetServer/main.cpp | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/Servers/TelnetServer/Client.cpp b/Servers/TelnetServer/Client.cpp index 6c71ac3231..a813849a47 100644 --- a/Servers/TelnetServer/Client.cpp +++ b/Servers/TelnetServer/Client.cpp @@ -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)) { diff --git a/Servers/TelnetServer/Client.h b/Servers/TelnetServer/Client.h index 60e222cc98..83e9ec32f9 100644 --- a/Servers/TelnetServer/Client.h +++ b/Servers/TelnetServer/Client.h @@ -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 }; diff --git a/Servers/TelnetServer/main.cpp b/Servers/TelnetServer/main.cpp index d8cfd364c8..e932fccad7 100644 --- a/Servers/TelnetServer/main.cpp +++ b/Servers/TelnetServer/main.cpp @@ -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; |