From dc77d62a5d1fa3ffdb2efa2c907be232267e4d79 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Tue, 28 Jul 2020 10:32:18 -0700 Subject: [PATCH] (ixcobra) CobraConnection: unsubscribe from all subscriptions when disconnecting --- docs/CHANGELOG.md | 4 ++++ ixcobra/ixcobra/IXCobraConnection.cpp | 18 ++++++++++++++++++ ixcobra/ixcobra/IXCobraConnection.h | 3 +++ ixwebsocket/IXWebSocketVersion.h | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9c53d1cc..d29b6cf1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All changes to this project will be documented in this file. +## [10.0.2] - 2020-07-28 + +(ixcobra) CobraConnection: unsubscribe from all subscriptions when disconnecting + ## [10.0.1] - 2020-07-27 (socket utility) move ix::getFreePort to ixwebsocket library diff --git a/ixcobra/ixcobra/IXCobraConnection.cpp b/ixcobra/ixcobra/IXCobraConnection.cpp index 9fc655e9..523993c2 100644 --- a/ixcobra/ixcobra/IXCobraConnection.cpp +++ b/ixcobra/ixcobra/IXCobraConnection.cpp @@ -111,6 +111,12 @@ namespace ix void CobraConnection::disconnect() { + auto subscriptionIds = getSubscriptionsIds(); + for (auto&& subscriptionId : subscriptionIds) + { + unsubscribe(subscriptionId); + } + _authenticated = false; _webSocket->stop(); } @@ -614,6 +620,18 @@ namespace ix _webSocket->send(pdu.toStyledString()); } + std::vector CobraConnection::getSubscriptionsIds() + { + std::vector subscriptionIds; + std::lock_guard lock(_cbsMutex); + + for (auto&& it : _cbs) + { + subscriptionIds.push_back(it.first); + } + return subscriptionIds; + } + // // Enqueue strategy drops old messages when we are at full capacity // diff --git a/ixcobra/ixcobra/IXCobraConnection.h b/ixcobra/ixcobra/IXCobraConnection.h index 755020a2..66d5df9a 100644 --- a/ixcobra/ixcobra/IXCobraConnection.h +++ b/ixcobra/ixcobra/IXCobraConnection.h @@ -163,6 +163,9 @@ namespace ix /// Tells whether the internal queue is empty or not bool isQueueEmpty(); + /// Retrieve all subscriptions ids + std::vector getSubscriptionsIds(); + /// /// Member variables /// diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index ba2c25d3..f6486f34 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.0.1" +#define IX_WEBSOCKET_VERSION "10.0.2"