/* * Copyright (c) 2021, Dex♪ * Copyright (c) 2022, Ali Mohammad Pur * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace WebSocket { class WebSocketImpl : public Core::Object { C_OBJECT(WebSocketImpl); public: virtual ~WebSocketImpl() override = default; explicit WebSocketImpl(Core::Object* parent = nullptr); void connect(ConnectionInfo const&); bool can_read_line() { return MUST(m_socket->can_read_line()); } ErrorOr read_line(size_t size); bool can_read() { return MUST(m_socket->can_read_without_blocking()); } ErrorOr read(int max_size); bool send(ReadonlyBytes bytes) { return m_socket->write_or_error(bytes); } bool eof() { return m_socket->is_eof(); } void discard_connection() { m_socket.clear(); } Function on_connected; Function on_connection_error; Function on_ready_to_read; private: OwnPtr m_socket; }; }