summaryrefslogtreecommitdiff
path: root/Userland/Services/EchoServer/Client.h
blob: c7a5680cc6ccfe213fc0910db6c637e8b2b42459 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright (c) 2020, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <LibCore/Socket.h>

class Client : public RefCounted<Client> {
public:
    static NonnullRefPtr<Client> create(int id, NonnullOwnPtr<Core::TCPSocket> socket)
    {
        return adopt_ref(*new Client(id, move(socket)));
    }

    Function<void()> on_exit;

protected:
    Client(int id, NonnullOwnPtr<Core::TCPSocket> socket);

    ErrorOr<void> drain_socket();
    void quit();

private:
    int m_id { 0 };
    NonnullOwnPtr<Core::TCPSocket> m_socket;
};