diff options
author | Javier <dev.git@javispedro.com> | 2015-12-26 20:19:10 +0100 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2015-12-26 20:19:10 +0100 |
commit | 36ec2c13b4d519231794c2262818e48526074f94 (patch) | |
tree | 28400cc79c007b927d745b01af9437282fa8ffd1 | |
parent | ceafe544919a35f674684c2e71593b9fb35747a5 (diff) | |
download | sapd-36ec2c13b4d519231794c2262818e48526074f94.tar.gz sapd-36ec2c13b4d519231794c2262818e48526074f94.zip |
fix a crash while disconnecting
-rw-r--r-- | sappeer.cc | 43 |
1 files changed, 25 insertions, 18 deletions
@@ -110,7 +110,15 @@ bool SAPPeer::terminateServiceConnection(const QString &profile, const QString & SAPConnection *conn = _conns.value(profile, 0); if (conn) { - // TODO send terminaterequest message + SAProtocol::ServiceTerminationRequestFrame request; + request.messageType = SAProtocol::ServiceTerminationRequest; + request.initiatorId = initiator; + request.acceptorId = acceptor; + request.profile = profile; + + writeDataToSession(SAProtocol::defaultSessionId, + SAProtocol::packServiceTerminationRequestFrame(request)); + return true; } else { qWarning() << "Connection does not exist:" << profile; @@ -179,7 +187,6 @@ void SAPPeer::acceptServiceConnection(SAPConnectionRequest *connReq, int statusC // Cancel any partial opened sessions foreach (SAPSocket *socket, conn->sockets()) { _sessions.remove(socket->sessionId()); - delete socket; } _conns.remove(conn->profile()); delete conn; @@ -232,9 +239,9 @@ void SAPPeer::handleDisconnected() // Clear out all active sessions emit disconnected(); qDeleteAll(_conns); - qDeleteAll(_sessions); - _conns.clear(); + // Deleting connections will clean up all sockets too. _sessions.clear(); + _conns.clear(); // TODO Figure out who should actually reconnect } @@ -349,26 +356,27 @@ void SAPPeer::handleDefaultSessionMessage(const QByteArray &message) SAPConnection *conn = firstSocket->connection(); - foreach (int session, frame.sessions) { - SAPSocket *socket = _sessions.value(session, 0); - if (socket) { - if (socket->isOpen()) { - qWarning() << "Session" << session << "was already open?"; + if (ok) { + foreach (int session, frame.sessions) { + SAPSocket *socket = _sessions.value(session, 0); + if (socket) { + if (socket->isOpen()) { + qWarning() << "Session" << session << "was already open?"; + } + + qDebug() << "Session" << session << "now live"; + socket->setOpen(true); + emit socket->connected(); + } else { + qWarning() << "Unknown session id:" << session; } - - qDebug() << "Session" << session << "now live"; - socket->setOpen(true); - emit socket->connected(); - } else { - qWarning() << "Unknown session id:" << session; } - } - if (ok) { emit conn->connected(); } else { emit conn->error(frame.statusCode); emit conn->disconnected(); + delete conn; } break; @@ -399,7 +407,6 @@ void SAPPeer::handleDefaultSessionMessage(const QByteArray &message) foreach (SAPSocket *socket, conn->sockets()) { emit socket->disconnected(); _sessions.remove(socket->sessionId()); - delete socket; } emit conn->disconnected(); _conns.remove(conn->profile()); |