From bc6f9fc6d980f6bd7ae7951d34341cee0665e7b4 Mon Sep 17 00:00:00 2001 From: lanthora Date: Mon, 1 Jul 2024 16:14:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20PollSet=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 +++------- src/websocket/client.cc | 17 ++--------------- src/websocket/client.h | 2 -- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 29bc7417..f7109f18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.18.4) -project(candy LANGUAGES C CXX VERSION 5.9.2) +project(candy LANGUAGES C CXX VERSION 5.9.3) option(CANDY_NOEXE "Don't build executable") option(CANDY_DEVEL "Build development library") @@ -105,14 +105,10 @@ if (${CANDY_STATIC_POCO}) set(ENABLE_ZIP OFF CACHE BOOL "" FORCE) set(ENABLE_JWT OFF CACHE BOOL "" FORCE) include(FetchContent) - - set(CANDY_POCO_REPOSITORY "https://github.com/pocoproject/poco.git" CACHE STRING "") - set(CANDY_POCO_TAG "poco-1.13.3-release" CACHE STRING "") - FetchContent_Declare( poco - GIT_REPOSITORY ${CANDY_POCO_REPOSITORY} - GIT_TAG ${CANDY_POCO_TAG} + GIT_REPOSITORY "https://github.com/pocoproject/poco.git" + GIT_TAG "poco-1.13.3-release" ) FetchContent_GetProperties(poco) if(NOT poco_POPULATED) diff --git a/src/websocket/client.cc b/src/websocket/client.cc index 6207f13b..32c0c136 100644 --- a/src/websocket/client.cc +++ b/src/websocket/client.cc @@ -1,11 +1,11 @@ // SPDX-License-Identifier: MIT #include "websocket/client.h" #include "utility/time.h" +#include #include #include #include #include -#include #include #include #include @@ -22,13 +22,6 @@ int WebSocketClient::connect(const std::string &address) { return -1; } - try { - this->pollSet = std::make_shared(); - } catch (Poco::Net::ServiceNotFoundException &e) { - spdlog::critical("create poll set failed: {}: {}", e.what(), e.message()); - return -1; - } - try { const std::string path = uri->getPath().empty() ? "/" : uri->getPath(); Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, path, Poco::Net::HTTPMessage::HTTP_1_1); @@ -45,7 +38,6 @@ int WebSocketClient::connect(const std::string &address) { spdlog::critical("invalid websocket scheme: {}", address); return -1; } - this->pollSet->add(*this->ws.get(), Poco::Net::PollSet::POLL_READ); this->timestamp = Time::bootTime(); return 0; } catch (std::exception &e) { @@ -56,10 +48,6 @@ int WebSocketClient::connect(const std::string &address) { int WebSocketClient::disconnect() { try { - if (this->pollSet) { - this->pollSet->clear(); - this->pollSet.reset(); - } if (this->ws) { this->ws->shutdown(); this->ws->close(); @@ -83,8 +71,7 @@ int WebSocketClient::read(WebSocketMessage &message) { } try { - Poco::Net::PollSet::SocketModeMap socketModeMap = this->pollSet->poll(Poco::Timespan(this->timeout, 0)); - if (socketModeMap.empty()) { + if (!this->ws->poll(Poco::Timespan(this->timeout, 0), Poco::Net::Socket::SELECT_READ)) { if (Time::bootTime() - this->timestamp > 30000) { message.type = WebSocketMessageType::Error; message.buffer = "websocket pong timeout"; diff --git a/src/websocket/client.h b/src/websocket/client.h index 088ecf26..7642962a 100644 --- a/src/websocket/client.h +++ b/src/websocket/client.h @@ -3,7 +3,6 @@ #define CANDY_WEBSOCKET_CLIENT_H #include "websocket/common.h" -#include #include #include @@ -30,7 +29,6 @@ class WebSocketClient { int sendPingMessage(WebSocketMessage &message); int timeout; - std::shared_ptr pollSet; std::shared_ptr ws; int64_t timestamp; std::string pingMessage;