mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +00:00
dbd25916a3
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.
29 lines
608 B
C++
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;
|
|
};
|