From 704fca969f82ff81d0002c1122fa0921a3037e3d Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 20 Nov 2019 12:05:32 -0500 Subject: [PATCH] handle accept errors --- libi2pd/NTCP2.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libi2pd/NTCP2.cpp b/libi2pd/NTCP2.cpp index 5183bbe6..fd20d35c 100644 --- a/libi2pd/NTCP2.cpp +++ b/libi2pd/NTCP2.cpp @@ -1345,15 +1345,19 @@ namespace transport { conn->ServerLogin (); m_PendingIncomingSessions.push_back (conn); + conn = nullptr; } } else LogPrint (eLogError, "NTCP2: Connected from error ", ec.message ()); } + else + LogPrint (eLogError, "NTCP2: Accept error ", error.message ()); if (error != boost::asio::error::operation_aborted) { - conn = std::make_shared (*this); + if (!conn) // connection is used + conn = std::make_shared (*this); m_NTCP2Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAccept, this, conn, std::placeholders::_1)); } @@ -1409,13 +1413,13 @@ namespace transport // pending for (auto it = m_PendingIncomingSessions.begin (); it != m_PendingIncomingSessions.end ();) { - if ((*it)->IsEstablished () || (*it)->IsTerminated ()) - it = m_PendingIncomingSessions.erase (it); // established or terminated - else if ((*it)->IsTerminationTimeoutExpired (ts)) + if ((*it)->IsEstablished () || (*it)->IsTerminationTimeoutExpired (ts)) { (*it)->Terminate (); - it = m_PendingIncomingSessions.erase (it); // expired + it = m_PendingIncomingSessions.erase (it); // etsablished of expired } + else if ((*it)->IsTerminated ()) + it = m_PendingIncomingSessions.erase (it); // already terminated else it++; }