diff --git a/SAM.cpp b/SAM.cpp index 017a7634..b6bc8a85 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -778,13 +778,14 @@ namespace client void SAMSession::CloseStreams () { + std::vector > socks; { std::lock_guard lock(m_SocketsMutex); - for (auto& sock : m_Sockets) { - sock->CloseStream(); + for (const auto& sock : m_Sockets) { + socks.push_back(sock); } } - // XXX: should this be done inside locked parts? + for (auto & sock : socks ) sock->Terminate(); m_Sockets.clear(); } diff --git a/SAM.h b/SAM.h index db6991f5..f1e63e0d 100644 --- a/SAM.h +++ b/SAM.h @@ -87,9 +87,9 @@ namespace client void SetSocketType (SAMSocketType socketType) { m_SocketType = socketType; }; SAMSocketType GetSocketType () const { return m_SocketType; }; + void Terminate (); private: - void Terminate (); void HandleHandshakeReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred); void HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred); void HandleMessage (const boost::system::error_code& ecode, std::size_t bytes_transferred); @@ -143,13 +143,13 @@ namespace client std::mutex m_SocketsMutex; /** safely add a socket to this session */ - void AddSocket(std::shared_ptr sock) { + void AddSocket(const std::shared_ptr & sock) { std::lock_guard lock(m_SocketsMutex); m_Sockets.push_back(sock); } /** safely remove a socket from this session */ - void DelSocket(std::shared_ptr sock) { + void DelSocket(const std::shared_ptr & sock) { std::lock_guard lock(m_SocketsMutex); m_Sockets.remove(sock); }