mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-08-27 22:35:02 +00:00
avoid possible double termination. Use atomic swap
This commit is contained in:
+2
-2
@@ -563,9 +563,9 @@ namespace transport
|
||||
|
||||
void NTCP2Session::Terminate ()
|
||||
{
|
||||
if (!m_IsTerminated)
|
||||
bool isTerminated = m_IsTerminated.exchange (true);
|
||||
if (!isTerminated)
|
||||
{
|
||||
m_IsTerminated = true;
|
||||
m_IsEstablished = false;
|
||||
boost::system::error_code ec;
|
||||
m_Socket.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
|
||||
|
||||
+2
-1
@@ -15,6 +15,7 @@
|
||||
#include <map>
|
||||
#include <array>
|
||||
#include <random>
|
||||
#include <atomic>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <boost/asio.hpp>
|
||||
@@ -222,7 +223,7 @@ namespace transport
|
||||
NTCP2Server& m_Server;
|
||||
boost::asio::ip::tcp::socket m_Socket;
|
||||
boost::asio::ip::tcp::endpoint m_RemoteEndpoint;
|
||||
bool m_IsEstablished, m_IsTerminated;
|
||||
std::atomic<bool> m_IsEstablished, m_IsTerminated;
|
||||
|
||||
std::unique_ptr<NTCP2Establisher> m_Establisher;
|
||||
// data phase
|
||||
|
||||
Reference in New Issue
Block a user