diff --git a/kit/Kit.cpp b/kit/Kit.cpp index f10493e50..284e552f3 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -1623,19 +1623,7 @@ class KitSocketPoll final : public SocketPoll public: ~KitSocketPoll() { -#ifdef IOS - std::unique_lock lock(KSPollsMutex); - std::shared_ptr p; - auto i = KSPolls.begin(); - for (; i != KSPolls.end(); ++i) - { - p = i->lock(); - if (p && p.get() == this) - break; - } - assert(i != KSPolls.end()); - KSPolls.erase(i); -#endif + // Just to make it easier to set a breakpoint } static std::shared_ptr create() @@ -1645,7 +1633,6 @@ public: #ifdef IOS std::unique_lock lock(KSPollsMutex); KSPolls.push_back(result); - // KSPollsCV.notify_one(); #endif return result; } @@ -1762,6 +1749,11 @@ public: { } + ~KitWebSocketHandler() + { + // Just to make it easier to set a breakpoint + } + protected: void handleMessage(const std::vector& data) override { @@ -1881,10 +1873,13 @@ protected: SigUtil::setTerminationFlag(); #endif #ifdef IOS - std::unique_lock lock(_ksPoll->terminationMutex); - _ksPoll->terminationFlag = true; - _ksPoll->terminationCV.notify_all(); + { + std::unique_lock lock(_ksPoll->terminationMutex); + _ksPoll->terminationFlag = true; + _ksPoll->terminationCV.notify_all(); + } #endif + _ksPoll.reset(); } }; @@ -1903,22 +1898,20 @@ int pollCallback(void* pData, int timeoutUs) return reinterpret_cast(pData)->kitPoll(timeoutUs); #else std::unique_lock lock(KitSocketPoll::KSPollsMutex); - if (KitSocketPoll::KSPolls.size() == 0) + std::vector> v; + for (const auto &i : KitSocketPoll::KSPolls) + { + auto p = i.lock(); + if (p) + v.push_back(p); + } + lock.unlock(); + if (v.size() == 0) { - // KitSocketPoll::KSPollsCV.wait(lock); - lock.unlock(); std::this_thread::sleep_for(std::chrono::microseconds(timeoutUs)); } else { - std::vector> v; - for (const auto &i : KitSocketPoll::KSPolls) - { - auto p = i.lock(); - if (p) - v.push_back(p); - } - lock.unlock(); for (const auto &p : v) p->kitPoll(timeoutUs); } diff --git a/net/Socket.hpp b/net/Socket.hpp index 9ee336950..84b4bfafd 100644 --- a/net/Socket.hpp +++ b/net/Socket.hpp @@ -799,6 +799,7 @@ public: { assertCorrectThread(); _socketHandler->onDisconnect(); + _socketHandler.reset(); } if (!_shutdownSignalled)