mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-05 05:44:13 +00:00
fixed crash
This commit is contained in:
parent
335de27095
commit
4dc33a6f45
31
SAM.cpp
31
SAM.cpp
@ -25,18 +25,22 @@ namespace client
|
|||||||
|
|
||||||
SAMSocket::~SAMSocket ()
|
SAMSocket::~SAMSocket ()
|
||||||
{
|
{
|
||||||
if (m_Stream)
|
Terminate ();
|
||||||
i2p::stream::DeleteStream (m_Stream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SAMSocket::Terminate ()
|
void SAMSocket::CloseStream ()
|
||||||
{
|
{
|
||||||
if (m_Stream)
|
if (m_Stream)
|
||||||
|
{
|
||||||
m_Stream->Close ();
|
m_Stream->Close ();
|
||||||
|
i2p::stream::DeleteStream (m_Stream);
|
||||||
// TODO: make this swap atomic
|
m_Stream = nullptr;
|
||||||
auto session = m_Session;
|
}
|
||||||
m_Session = nullptr;
|
}
|
||||||
|
|
||||||
|
void SAMSocket::Terminate ()
|
||||||
|
{
|
||||||
|
CloseStream ();
|
||||||
|
|
||||||
switch (m_SocketType)
|
switch (m_SocketType)
|
||||||
{
|
{
|
||||||
@ -45,22 +49,23 @@ namespace client
|
|||||||
break;
|
break;
|
||||||
case eSAMSocketTypeStream:
|
case eSAMSocketTypeStream:
|
||||||
{
|
{
|
||||||
if (session)
|
if (m_Session)
|
||||||
session->sockets.remove (shared_from_this ());
|
m_Session->sockets.remove (shared_from_this ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case eSAMSocketTypeAcceptor:
|
case eSAMSocketTypeAcceptor:
|
||||||
{
|
{
|
||||||
if (session)
|
if (m_Session)
|
||||||
{
|
{
|
||||||
session->sockets.remove (shared_from_this ());
|
m_Session->sockets.remove (shared_from_this ());
|
||||||
session->localDestination->StopAcceptingStreams ();
|
m_Session->localDestination->StopAcceptingStreams ();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
m_SocketType = eSAMSocketTypeTerminated;
|
||||||
m_Socket.close ();
|
m_Socket.close ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -670,6 +675,8 @@ namespace client
|
|||||||
auto it = m_Sessions.find (id);
|
auto it = m_Sessions.find (id);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
{
|
{
|
||||||
|
for (auto it1: it->second.sockets)
|
||||||
|
it1->CloseStream ();
|
||||||
it->second.sockets.clear ();
|
it->second.sockets.clear ();
|
||||||
it->second.localDestination->Stop ();
|
it->second.localDestination->Stop ();
|
||||||
m_Sessions.erase (it);
|
m_Sessions.erase (it);
|
||||||
|
6
SAM.h
6
SAM.h
@ -60,7 +60,8 @@ namespace client
|
|||||||
eSAMSocketTypeUnknown,
|
eSAMSocketTypeUnknown,
|
||||||
eSAMSocketTypeSession,
|
eSAMSocketTypeSession,
|
||||||
eSAMSocketTypeStream,
|
eSAMSocketTypeStream,
|
||||||
eSAMSocketTypeAcceptor
|
eSAMSocketTypeAcceptor,
|
||||||
|
eSAMSocketTypeTerminated
|
||||||
};
|
};
|
||||||
|
|
||||||
class SAMBridge;
|
class SAMBridge;
|
||||||
@ -71,7 +72,8 @@ namespace client
|
|||||||
|
|
||||||
SAMSocket (SAMBridge& owner);
|
SAMSocket (SAMBridge& owner);
|
||||||
~SAMSocket ();
|
~SAMSocket ();
|
||||||
|
void CloseStream (); // TODO: implement it better
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
||||||
void ReceiveHandshake ();
|
void ReceiveHandshake ();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user