1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01:00

Do not delete connection if PeerInfo disappers during connect

This commit is contained in:
Uwe L. Korn 2013-06-04 21:26:01 +02:00
parent 8610c156eb
commit 18e1340de9
3 changed files with 17 additions and 1 deletions

View File

@ -116,6 +116,7 @@ ConnectionManager::connectToPeer( const Tomahawk::peerinfo_ptr &peerInfo, bool l
m["nodeid"] = Database::instance()->impl()->dbid();
m_controlConnection = QPointer<ControlConnection>( new ControlConnection( Servent::instance() ) );
m_controlConnection->setShutdownOnEmptyPeerInfos( false );
m_controlConnection->addPeerInfo( peerInfo );
m_controlConnection->setFirstMessage( m );
@ -238,6 +239,8 @@ ConnectionManager::handoverSocket( QTcpSocketExtra* sock )
m_controlConnection->setPeerPort( sock->peerPort() );
m_controlConnection->start( sock );
// ControlConntection is now connected, now it can be destroyed if the PeerInfos disappear
m_controlConnection->setShutdownOnEmptyPeerInfos( true );
m_currentPeerInfo.clear();
m_mutex.unlock();
}

View File

@ -39,6 +39,7 @@ ControlConnection::ControlConnection( Servent* parent )
, m_dbsyncconn( 0 )
, m_registered( false )
, m_pingtimer( 0 )
, m_shutdownOnEmptyPeerInfos( true )
{
qDebug() << "CTOR controlconnection";
setId("ControlConnection()");
@ -305,7 +306,17 @@ ControlConnection::removePeerInfo( const peerinfo_ptr& peerInfo )
m_peerInfos.remove( peerInfo );
if ( m_peerInfos.isEmpty() )
if ( m_peerInfos.isEmpty() && m_shutdownOnEmptyPeerInfos )
{
shutdown( true );
}
}
void
ControlConnection::setShutdownOnEmptyPeerInfos( bool shutdownOnEmptyPeerInfos )
{
m_shutdownOnEmptyPeerInfos = shutdownOnEmptyPeerInfos;
if ( m_peerInfos.isEmpty() && m_shutdownOnEmptyPeerInfos )
{
shutdown( true );
}

View File

@ -50,6 +50,7 @@ public:
void addPeerInfo( const Tomahawk::peerinfo_ptr& peerInfo );
void removePeerInfo( const Tomahawk::peerinfo_ptr& peerInfo );
void setShutdownOnEmptyPeerInfos( bool shutdownOnEmptyPeerInfos );
const QSet< Tomahawk::peerinfo_ptr > peerInfos() const;
protected:
@ -71,6 +72,7 @@ private:
QString m_dbconnkey;
bool m_registered;
bool m_shutdownOnEmptyPeerInfos;
QTimer* m_pingtimer;
QTime m_pingtimer_mark;