Close all connections
| 87 | |
| 88 | // Close all connections |
| 89 | void ConnectionManager::Shutdown() |
| 90 | { |
| 91 | // sml::PrintDebug("Shutting down connection manager") ; |
| 92 | |
| 93 | // Stop the thread (and wait until it has stopped) |
| 94 | if (m_ListenerThread) |
| 95 | { |
| 96 | m_ListenerThread->Stop(true) ; |
| 97 | |
| 98 | // Remove the listener |
| 99 | delete m_ListenerThread ; |
| 100 | m_ListenerThread = NULL ; |
| 101 | } |
| 102 | |
| 103 | // sml::PrintDebug("Listener stopped") ; |
| 104 | |
| 105 | // Stop the receiver thread (and wait until is has stopped) |
| 106 | if (m_ReceiverThread) |
| 107 | { |
| 108 | m_ReceiverThread->Stop(true) ; |
| 109 | |
| 110 | // sml::PrintDebug("Receiver stopped") ; |
| 111 | |
| 112 | // Remove the thread |
| 113 | delete m_ReceiverThread ; |
| 114 | m_ReceiverThread = NULL ; |
| 115 | } |
| 116 | |
| 117 | // Serialize thread access to the connections list |
| 118 | soar_thread::Lock lock(&m_ConnectionsMutex) ; |
| 119 | |
| 120 | for (ConnectionsIter iter = m_Connections.begin() ; iter != m_Connections.end() ; iter++) |
| 121 | { |
| 122 | Connection* pConnection = *iter ; |
| 123 | pConnection->CloseConnection() ; |
| 124 | |
| 125 | // Remove any events that this connection is listening to |
| 126 | KernelSML* pKernelSML = static_cast<KernelSML*>(pConnection->GetUserData()); |
| 127 | pKernelSML->RemoveAllListeners(pConnection) ; |
| 128 | |
| 129 | // Not clear that we can just delete connections as we might be inside a connection callback |
| 130 | // when the shutdown comes. So for safety, move connections to a closed list instead of deleting. |
| 131 | // For now this will leak the connection object. Later if we are confident we can delete this list. |
| 132 | //delete pConnection ; |
| 133 | m_ClosedConnections.push_back(pConnection) ; |
| 134 | } |
| 135 | |
| 136 | m_Connections.clear() ; |
| 137 | |
| 138 | // Now clean up all closed connections. |
| 139 | for (ConnectionsIter iter = m_ClosedConnections.begin() ; iter != m_ClosedConnections.end() ; iter++) |
| 140 | { |
| 141 | Connection* pConnection = *iter ; |
| 142 | delete pConnection ; |
| 143 | } |
| 144 | m_ClosedConnections.clear() ; |
| 145 | |
| 146 | // sml::PrintDebug("Completed shutdown") ; |
nothing calls this directly
no test coverage detected