Skip to content

Commit

Permalink
移除 PollSet 相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Jul 1, 2024
1 parent 1c49533 commit bc6f9fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 2 additions & 15 deletions src/websocket/client.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
#include "websocket/client.h"
#include "utility/time.h"
#include <Poco/Exception.h>
#include <Poco/Net/HTTPMessage.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/NetException.h>
#include <Poco/Timespan.h>
#include <Poco/URI.h>
#include <memory>
Expand All @@ -22,13 +22,6 @@ int WebSocketClient::connect(const std::string &address) {
return -1;
}

try {
this->pollSet = std::make_shared<Poco::Net::PollSet>();
} 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);
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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";
Expand Down
2 changes: 0 additions & 2 deletions src/websocket/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#define CANDY_WEBSOCKET_CLIENT_H

#include "websocket/common.h"
#include <Poco/Net/PollSet.h>
#include <Poco/Net/WebSocket.h>
#include <string>

Expand All @@ -30,7 +29,6 @@ class WebSocketClient {
int sendPingMessage(WebSocketMessage &message);

int timeout;
std::shared_ptr<Poco::Net::PollSet> pollSet;
std::shared_ptr<Poco::Net::WebSocket> ws;
int64_t timestamp;
std::string pingMessage;
Expand Down

0 comments on commit bc6f9fc

Please sign in to comment.