ladybird/Userland/Services/EchoServer/Client.h
sin-ack dbd25916a3 LibCore+Userland+Tests: Convert Stream APIs to construct on heap
As per previous discussion, it was decided that the Stream classes
should be constructed on the heap.

While I don't personally agree with this change, it does have the
benefit of avoiding Function object reconstructions due to the lambda
passed to Notifier pointing to a stale object reference. This also has
the benefit of not having to "box" objects for virtual usage, as the
objects come pre-boxed.

However, it means that we now hit the heap everytime we construct a
TCPSocket for instance, which might not be desirable.
2022-01-13 15:16:12 +03:30

29 lines
608 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibCore/Stream.h>
class Client : public RefCounted<Client> {
public:
static NonnullRefPtr<Client> create(int id, NonnullOwnPtr<Core::Stream::TCPSocket> socket)
{
return adopt_ref(*new Client(id, move(socket)));
}
Function<void()> on_exit;
protected:
Client(int id, NonnullOwnPtr<Core::Stream::TCPSocket> socket);
ErrorOr<void> drain_socket();
void quit();
private:
int m_id { 0 };
NonnullOwnPtr<Core::Stream::TCPSocket> m_socket;
};