Skip to content

Commit

Permalink
Merge pull request #838 from majestrate/sam-crash-fix-2017-03-29
Browse files Browse the repository at this point in the history
try fixing sam crashyness
  • Loading branch information
orignal committed Mar 29, 2017
2 parents 8c37c49 + 3a9a5ec commit 3d1b6e2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions SAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,13 +789,14 @@ namespace client

void SAMSession::CloseStreams ()
{
std::vector<std::shared_ptr<SAMSocket> > socks;
{
std::lock_guard<std::mutex> 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();
}

Expand Down
6 changes: 3 additions & 3 deletions SAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -143,13 +143,13 @@ namespace client
std::mutex m_SocketsMutex;

/** safely add a socket to this session */
void AddSocket(std::shared_ptr<SAMSocket> sock) {
void AddSocket(const std::shared_ptr<SAMSocket> & sock) {
std::lock_guard<std::mutex> lock(m_SocketsMutex);
m_Sockets.push_back(sock);
}

/** safely remove a socket from this session */
void DelSocket(std::shared_ptr<SAMSocket> sock) {
void DelSocket(const std::shared_ptr<SAMSocket> & sock) {
std::lock_guard<std::mutex> lock(m_SocketsMutex);
m_Sockets.remove(sock);
}
Expand Down

0 comments on commit 3d1b6e2

Please sign in to comment.