mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
try fixing sam crashyness
This commit is contained in:
parent
fdf11e6038
commit
3a9a5ec669
7
SAM.cpp
7
SAM.cpp
@ -778,13 +778,14 @@ namespace client
|
|||||||
|
|
||||||
void SAMSession::CloseStreams ()
|
void SAMSession::CloseStreams ()
|
||||||
{
|
{
|
||||||
|
std::vector<std::shared_ptr<SAMSocket> > socks;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
||||||
for (auto& sock : m_Sockets) {
|
for (const auto& sock : m_Sockets) {
|
||||||
sock->CloseStream();
|
socks.push_back(sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// XXX: should this be done inside locked parts?
|
for (auto & sock : socks ) sock->Terminate();
|
||||||
m_Sockets.clear();
|
m_Sockets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6
SAM.h
6
SAM.h
@ -87,9 +87,9 @@ namespace client
|
|||||||
void SetSocketType (SAMSocketType socketType) { m_SocketType = socketType; };
|
void SetSocketType (SAMSocketType socketType) { m_SocketType = socketType; };
|
||||||
SAMSocketType GetSocketType () const { return m_SocketType; };
|
SAMSocketType GetSocketType () const { return m_SocketType; };
|
||||||
|
|
||||||
|
void Terminate ();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Terminate ();
|
|
||||||
void HandleHandshakeReceived (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
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 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);
|
void HandleMessage (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||||
@ -143,13 +143,13 @@ namespace client
|
|||||||
std::mutex m_SocketsMutex;
|
std::mutex m_SocketsMutex;
|
||||||
|
|
||||||
/** safely add a socket to this session */
|
/** 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);
|
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
||||||
m_Sockets.push_back(sock);
|
m_Sockets.push_back(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** safely remove a socket from this session */
|
/** 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);
|
std::lock_guard<std::mutex> lock(m_SocketsMutex);
|
||||||
m_Sockets.remove(sock);
|
m_Sockets.remove(sock);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user