diff --git a/README.md b/README.md index 4f87914..9ac8d66 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,10 @@ ``` -## 依赖 +## 版本 ``` +v2.3 | 修复zcan没有回执的BUG ``` diff --git a/src/configs/version.hpp b/src/configs/version.hpp index c681d56..28d3f8e 100644 --- a/src/configs/version.hpp +++ b/src/configs/version.hpp @@ -1,2 +1,2 @@ #pragma once -#define VERSION "2.2" \ No newline at end of file +#define VERSION "2.3" \ No newline at end of file diff --git a/src/service/extapi_service.cpp b/src/service/extapi_service.cpp index 68f7a21..1c6b878 100644 --- a/src/service/extapi_service.cpp +++ b/src/service/extapi_service.cpp @@ -120,7 +120,7 @@ void ExtAPIService::initialize() { } string chname = webSocket.getUrl().substr(1); - WbesocketConnectMgrService::insertNewClient(chname, findws(chname), make_shared(connectionState->getRemoteIp())); + WbesocketConnectMgrService::insertNewClient(chname, findws(&webSocket), make_shared(connectionState->getRemoteIp())); } else if (msg->type == ix::WebSocketMessageType::Message) { string chname = webSocket.getUrl().substr(1); auto channel = DataChannelMgr::findByChannel(chname); @@ -132,7 +132,7 @@ void ExtAPIService::initialize() { } else if (msg->type == ix::WebSocketMessageType::Close) { string chname = webSocket.getUrl().substr(1); logger->info("close connect ip: {},url: {}, channel:{}", connectionState->getRemoteIp(), webSocket.getUrl(), chname); - WbesocketConnectMgrService::removeClient(chname, findws(chname)); + WbesocketConnectMgrService::removeClient(chname, findws(&webSocket)); } }); @@ -144,10 +144,15 @@ void ExtAPIService::initialize() { WbesocketConnectMgrService::findClientByName(fromch->getAlias(), clients); for (auto ch : clients) { if (ch) { + WebSocketSendInfo sendInfo; if (binary) { - ch->sendBinary(string(data, len)); + sendInfo = ch->sendBinary(string(data, len)); } else { - ch->sendText(string(data, len)); + sendInfo = ch->sendText(string(data, len)); + } + + if (!sendInfo.success) { + logger->error("send data to client {} failed", (int64_t)ch.get()); } } } @@ -184,12 +189,12 @@ void ExtAPIService::initialize() { logger->info("======================================================"); }; -shared_ptr ExtAPIService::findws(string chname) { - if (chname.empty()) return nullptr; +shared_ptr ExtAPIService::findws(WebSocket *ws) { + if (!ws) return nullptr; auto clients = m_wsServer->getClients(); for (auto it : clients) { - if (it->getUrl().substr(1) == chname) { + if (it.get() == ws) { return it; } } diff --git a/src/service/extapi_service.hpp b/src/service/extapi_service.hpp index d3449d2..603e3fe 100644 --- a/src/service/extapi_service.hpp +++ b/src/service/extapi_service.hpp @@ -48,6 +48,6 @@ class ExtAPIService { void initialize(); private: - shared_ptr findws(string chname); + shared_ptr findws(WebSocket* ws); }; } // namespace iflytop \ No newline at end of file diff --git a/src/service/wbesocket_connect_mgr_service.cpp b/src/service/wbesocket_connect_mgr_service.cpp index 306fba0..1343bcf 100644 --- a/src/service/wbesocket_connect_mgr_service.cpp +++ b/src/service/wbesocket_connect_mgr_service.cpp @@ -48,9 +48,22 @@ void WbesocketConnectMgrService::findClientByName(string chname, list> rmoveClients; + for (auto ch : it->second) { + if (ch->getReadyState() == ix::ReadyState::Closed || ch->getReadyState() == ix::ReadyState::Closing) { + rmoveClients.push_back(ch); + continue; + } clients.push_back(ch); } + + for (auto ch : rmoveClients) { + it->second.remove(ch); + wsClientsInfo.erase((void *)ch.get()); + GET_LOGGER(WSConnectMgr)->info("remove client: {} {}, channel: {}", ch->getUrl(), (void *)ch.get(), chname); + } + } json WbesocketConnectMgrService::getConnectionList() { diff --git a/src/service/wbesocket_connect_mgr_service.hpp b/src/service/wbesocket_connect_mgr_service.hpp index a6519e5..f4e52dc 100644 --- a/src/service/wbesocket_connect_mgr_service.hpp +++ b/src/service/wbesocket_connect_mgr_service.hpp @@ -45,6 +45,8 @@ class WbesocketConnectMgrService { static void removeClient(string chname, shared_ptr client); static void findClientByName(string chname, list> &clients); static json getConnectionList(); + + static void updateConnectList(); }; } // namespace iflytop