From afdc699fb76bb947645c9bf9e0cec807d02fb871 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 28 May 2023 09:38:05 +0800 Subject: [PATCH] 1 --- a8/websocketclient.cc | 30 +++++++++++++++++++++++++++++- a8/websocketclient.h | 16 ++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/a8/websocketclient.cc b/a8/websocketclient.cc index f773e16..1605687 100644 --- a/a8/websocketclient.cc +++ b/a8/websocketclient.cc @@ -7,8 +7,9 @@ namespace a8 { - WebSocketClient::WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port): AsioTcpClient(io_context, remote_ip, remote_port) + WebSocketClient::WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port) { + tcp_client_ = std::make_shared(io_context, remote_ip, remote_port); decoded_buff_ = (char *)malloc(1024 * 64 + 1); decoded_bufflen_ = 0; } @@ -20,6 +21,33 @@ namespace a8 decoded_bufflen_ = 0; } + void WebSocketClient::Open() + { + tcp_client_->Open(); + } + + void WebSocketClient::Close() + { + tcp_client_->Close(); + } + + bool WebSocketClient::IsActive() + { + return tcp_client_->IsActive(); + } + + bool WebSocketClient::Connected() + { + return tcp_client_->Connected(); + } + + void WebSocketClient::SendBuff(const char* buff, unsigned int bufflen) + { + if (!handshook_) { + abort(); + } + } + } #endif diff --git a/a8/websocketclient.h b/a8/websocketclient.h index 2d74705..20be4cc 100644 --- a/a8/websocketclient.h +++ b/a8/websocketclient.h @@ -11,13 +11,25 @@ using asio::ip::tcp; namespace a8 { - class WebSocketClient : public AsioTcpClient + class WebSocketClient { public: WebSocketClient(asio::io_context& io_context, const std::string& remote_ip, int remote_port); - virtual ~WebSocketClient() override; + virtual ~WebSocketClient(); + + std::function on_error; + std::function on_connect; + std::function on_disconnect; + std::function on_socketread; + + void Open(); + void Close(); + bool IsActive(); + bool Connected(); + void SendBuff(const char* buff, unsigned int bufflen); private: + std::shared_ptr tcp_client_; char *decoded_buff_ = nullptr; int decoded_bufflen_ = 0; bool handshook_ = false;