mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibWebSocket: Switch to using Core::Stream
As LibTLS now supports the Core::Stream APIs, we can get rid of the split paths for TCP/TLS and significantly simplify the code as well. Provided to you free of charge by the Core::Stream-ification team :^)
This commit is contained in:
parent
d66c513131
commit
3f614a8fca
11 changed files with 142 additions and 348 deletions
50
Userland/Libraries/LibWebSocket/Impl/WebSocketImpl.h
Normal file
50
Userland/Libraries/LibWebSocket/Impl/WebSocketImpl.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Dex♪ <dexes.ttp@gmail.com>
|
||||
* Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/Object.h>
|
||||
#include <LibWebSocket/ConnectionInfo.h>
|
||||
|
||||
namespace WebSocket {
|
||||
|
||||
class WebSocketImpl : public Core::Object {
|
||||
C_OBJECT(WebSocketImpl);
|
||||
|
||||
public:
|
||||
virtual ~WebSocketImpl() override;
|
||||
explicit WebSocketImpl(Core::Object* parent = nullptr);
|
||||
|
||||
void connect(ConnectionInfo const&);
|
||||
|
||||
bool can_read_line() { return MUST(m_socket->can_read_line()); }
|
||||
ErrorOr<String> read_line(size_t size);
|
||||
|
||||
bool can_read() { return MUST(m_socket->can_read_without_blocking()); }
|
||||
ErrorOr<ByteBuffer> 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<void()> on_connected;
|
||||
Function<void()> on_connection_error;
|
||||
Function<void()> on_ready_to_read;
|
||||
|
||||
private:
|
||||
OwnPtr<Core::Stream::BufferedSocketBase> m_socket;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue