Browse Source

fixed race condition

pull/102/head
orignal 10 years ago
parent
commit
9750fb73b5
  1. 2
      NetDb.cpp
  2. 33
      Streaming.cpp

2
NetDb.cpp

@ -102,7 +102,7 @@ namespace data @@ -102,7 +102,7 @@ namespace data
{
try
{
I2NPMessage * msg = m_Queue.GetNextWithTimeout (10000); // 10 sec
I2NPMessage * msg = m_Queue.GetNextWithTimeout (30000); // 30 sec
if (msg)
{
while (msg)

33
Streaming.cpp

@ -38,19 +38,24 @@ namespace stream @@ -38,19 +38,24 @@ namespace stream
Stream::~Stream ()
{
Close ();
m_ReceiveTimer.cancel ();
m_ResendTimer.cancel ();
while (!m_ReceiveQueue.empty ())
{
auto packet = m_ReceiveQueue.front ();
m_ReceiveQueue.pop ();
delete packet;
}
for (auto it: m_SavedPackets)
delete it;
m_ReceiveTimer.cancel ();
for (auto it: m_SentPackets)
delete it;
m_SentPackets.clear ();
m_ResendTimer.cancel ();
for (auto it: m_SavedPackets)
delete it;
m_SavedPackets.clear ();
Close ();
}
void Stream::HandleNextPacket (Packet * packet)
@ -387,10 +392,13 @@ namespace stream @@ -387,10 +392,13 @@ namespace stream
if (packet)
{
SendPackets (std::vector<Packet *> { packet });
if (m_IsOpen)
{
bool isEmpty = m_SentPackets.empty ();
m_SentPackets.insert (packet);
if (isEmpty)
ScheduleResend ();
}
return true;
}
else
@ -565,8 +573,12 @@ namespace stream @@ -565,8 +573,12 @@ namespace stream
StreamingDestination::~StreamingDestination ()
{
{
std::unique_lock<std::mutex> l(m_StreamsMutex);
for (auto it: m_Streams)
delete it.second;
m_Streams.clear ();
}
if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
delete m_LeaseSet;
@ -621,10 +633,14 @@ namespace stream @@ -621,10 +633,14 @@ namespace stream
if (stream)
{
std::unique_lock<std::mutex> l(m_StreamsMutex);
m_Streams.erase (stream->GetRecvStreamID ());
auto it = m_Streams.find (stream->GetRecvStreamID ());
if (it != m_Streams.end ())
{
m_Streams.erase (it);
delete stream;
}
}
}
const i2p::data::LeaseSet * StreamingDestination::GetLeaseSet ()
{
@ -738,10 +754,13 @@ namespace stream @@ -738,10 +754,13 @@ namespace stream
auto it = m_Destinations.find (destination->GetIdentHash ());
if (it != m_Destinations.end ())
{
delete it->second;
auto d = it->second;
{
std::unique_lock<std::mutex> l(m_DestinationsMutex);
m_Destinations.erase (it);
}
delete d;
}
}
StreamingDestination * StreamingDestinations::CreateNewLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic)

Loading…
Cancel
Save