@@ -119,15 +119,13 @@ Session::Session(const fs::path& private_key_file,
119119 : m_private_key_file{private_key_file},
120120 m_control_host{control_host},
121121 m_interrupt{interrupt},
122- m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)},
123122 m_transient{false }
124123{
125124}
126125
127126Session::Session (const CService& control_host, CThreadInterrupt* interrupt)
128127 : m_control_host{control_host},
129128 m_interrupt{interrupt},
130- m_control_sock{std::make_unique<Sock>(INVALID_SOCKET)},
131129 m_transient{true }
132130{
133131}
@@ -346,7 +344,7 @@ void Session::CheckControlSock()
346344 LOCK (m_mutex);
347345
348346 std::string errmsg;
349- if (!m_control_sock->IsConnected (errmsg)) {
347+ if (m_control_sock && !m_control_sock->IsConnected (errmsg)) {
350348 LogPrintLevel (BCLog::I2P, BCLog::Level::Debug, " Control socket error: %s\n " , errmsg);
351349 Disconnect ();
352350 }
@@ -395,7 +393,7 @@ Binary Session::MyDestination() const
395393void Session::CreateIfNotCreatedAlready ()
396394{
397395 std::string errmsg;
398- if (m_control_sock->IsConnected (errmsg)) {
396+ if (m_control_sock && m_control_sock ->IsConnected (errmsg)) {
399397 return ;
400398 }
401399
@@ -468,14 +466,14 @@ std::unique_ptr<Sock> Session::StreamAccept()
468466
469467void Session::Disconnect ()
470468{
471- if (m_control_sock-> Get () != INVALID_SOCKET ) {
469+ if (m_control_sock) {
472470 if (m_session_id.empty ()) {
473471 LogPrintLevel (BCLog::I2P, BCLog::Level::Info, " Destroying incomplete SAM session\n " );
474472 } else {
475473 LogPrintLevel (BCLog::I2P, BCLog::Level::Info, " Destroying SAM session %s\n " , m_session_id);
476474 }
475+ m_control_sock.reset ();
477476 }
478- m_control_sock = std::make_unique<Sock>(INVALID_SOCKET);
479477 m_session_id.clear ();
480478}
481479} // namespace sam
0 commit comments