|
|
@ -47,10 +47,8 @@ namespace client |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eSAMSocketTypeStream: |
|
|
|
case eSAMSocketTypeStream: |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_Session) { |
|
|
|
if (m_Session) |
|
|
|
m_Session->DelSocket (shared_from_this ()); |
|
|
|
m_Session->DelSocket (shared_from_this ()); |
|
|
|
m_Session = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
case eSAMSocketTypeAcceptor: |
|
|
|
case eSAMSocketTypeAcceptor: |
|
|
@ -59,7 +57,6 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Session->DelSocket (shared_from_this ()); |
|
|
|
m_Session->DelSocket (shared_from_this ()); |
|
|
|
m_Session->localDestination->StopAcceptingStreams (); |
|
|
|
m_Session->localDestination->StopAcceptingStreams (); |
|
|
|
m_Session = nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -68,6 +65,7 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
m_SocketType = eSAMSocketTypeTerminated; |
|
|
|
m_SocketType = eSAMSocketTypeTerminated; |
|
|
|
if (m_Socket.is_open()) m_Socket.close (); |
|
|
|
if (m_Socket.is_open()) m_Socket.close (); |
|
|
|
|
|
|
|
m_Session = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SAMSocket::ReceiveHandshake () |
|
|
|
void SAMSocket::ReceiveHandshake () |
|
|
@ -721,7 +719,7 @@ namespace client |
|
|
|
m_IsRunning = false; |
|
|
|
m_IsRunning = false; |
|
|
|
m_Acceptor.cancel (); |
|
|
|
m_Acceptor.cancel (); |
|
|
|
for (auto it: m_Sessions) |
|
|
|
for (auto it: m_Sessions) |
|
|
|
delete it.second; |
|
|
|
it.second->CloseStreams (); |
|
|
|
m_Sessions.clear (); |
|
|
|
m_Sessions.clear (); |
|
|
|
m_Service.stop (); |
|
|
|
m_Service.stop (); |
|
|
|
if (m_Thread) |
|
|
|
if (m_Thread) |
|
|
@ -775,7 +773,7 @@ namespace client |
|
|
|
Accept (); |
|
|
|
Accept (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SAMSession * SAMBridge::CreateSession (const std::string& id, const std::string& destination, |
|
|
|
std::shared_ptr<SAMSession> SAMBridge::CreateSession (const std::string& id, const std::string& destination, |
|
|
|
const std::map<std::string, std::string> * params) |
|
|
|
const std::map<std::string, std::string> * params) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::shared_ptr<ClientDestination> localDestination = nullptr; |
|
|
|
std::shared_ptr<ClientDestination> localDestination = nullptr; |
|
|
@ -800,8 +798,9 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
if (localDestination) |
|
|
|
if (localDestination) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
auto session = std::make_shared<SAMSession>(localDestination); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
auto ret = m_Sessions.insert (std::pair<std::string, SAMSession *>(id, new SAMSession (localDestination))); |
|
|
|
auto ret = m_Sessions.insert (std::make_pair(id, session)); |
|
|
|
if (!ret.second) |
|
|
|
if (!ret.second) |
|
|
|
LogPrint (eLogWarning, "SAM: Session ", id, " already exists"); |
|
|
|
LogPrint (eLogWarning, "SAM: Session ", id, " already exists"); |
|
|
|
return ret.first->second; |
|
|
|
return ret.first->second; |
|
|
@ -811,19 +810,24 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
void SAMBridge::CloseSession (const std::string& id) |
|
|
|
void SAMBridge::CloseSession (const std::string& id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::shared_ptr<SAMSession> session; |
|
|
|
auto it = m_Sessions.find (id); |
|
|
|
{ |
|
|
|
if (it != m_Sessions.end ()) |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
|
|
|
|
auto it = m_Sessions.find (id); |
|
|
|
|
|
|
|
if (it != m_Sessions.end ()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
session = it->second; |
|
|
|
|
|
|
|
m_Sessions.erase (it); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto session = it->second; |
|
|
|
|
|
|
|
session->localDestination->StopAcceptingStreams (); |
|
|
|
session->localDestination->StopAcceptingStreams (); |
|
|
|
session->CloseStreams (); |
|
|
|
session->CloseStreams (); |
|
|
|
m_Sessions.erase (it); |
|
|
|
|
|
|
|
delete session; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SAMSession * SAMBridge::FindSession (const std::string& id) const |
|
|
|
std::shared_ptr<SAMSession> SAMBridge::FindSession (const std::string& id) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
auto it = m_Sessions.find (id); |
|
|
|
auto it = m_Sessions.find (id); |
|
|
|