summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWebSocket/Impl/TCPWebSocketConnectionImpl.h
blob: 1ece3f8befd7cdb8ff5e24c7700a81ac2feff031 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/ByteBuffer.h>
#include <AK/Span.h>
#include <AK/String.h>
#include <LibCore/Notifier.h>
#include <LibCore/Object.h>
#include <LibCore/TCPSocket.h>
#include <LibWebSocket/ConnectionInfo.h>
#include <LibWebSocket/Impl/AbstractWebSocketImpl.h>

namespace WebSocket {

class TCPWebSocketConnectionImpl final : public AbstractWebSocketImpl {
    C_OBJECT(TCPWebSocketConnectionImpl);

public:
    virtual ~TCPWebSocketConnectionImpl() override;

    virtual void connect(ConnectionInfo const& connection) override;

    virtual bool can_read_line() override;
    virtual String read_line(size_t size) override;

    virtual bool can_read() override;
    virtual ByteBuffer read(int max_size) override;

    virtual bool send(ReadonlyBytes data) override;

    virtual bool eof() override;

    virtual void discard_connection() override;

private:
    explicit TCPWebSocketConnectionImpl(Core::Object* parent = nullptr);

    RefPtr<Core::Notifier> m_notifier;
    RefPtr<Core::TCPSocket> m_socket;
};

}