Browse Source

close socket after if accept failed

pull/1441/head
orignal 5 years ago
parent
commit
0abb871f3f
  1. 4
      libi2pd/NTCP2.cpp
  2. 1
      libi2pd/NTCP2.h

4
libi2pd/NTCP2.cpp

@ -1356,8 +1356,10 @@ namespace transport
if (error != boost::asio::error::operation_aborted) if (error != boost::asio::error::operation_aborted)
{ {
if (!conn) // connection is used if (!conn) // connection is used, create new one
conn = std::make_shared<NTCP2Session> (*this); conn = std::make_shared<NTCP2Session> (*this);
else // reuse failed
conn->Close ();
m_NTCP2Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAccept, this, m_NTCP2Acceptor->async_accept(conn->GetSocket (), std::bind (&NTCP2Server::HandleAccept, this,
conn, std::placeholders::_1)); conn, std::placeholders::_1));
} }

1
libi2pd/NTCP2.h

@ -133,6 +133,7 @@ namespace transport
void Terminate (); void Terminate ();
void TerminateByTimeout (); void TerminateByTimeout ();
void Done (); void Done ();
void Close () { m_Socket.close (); }; // for accept
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; }; boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };

Loading…
Cancel
Save