diff --git a/src/libtomahawk/network/Connection.cpp b/src/libtomahawk/network/Connection.cpp index 03adfb45e..4981dae72 100644 --- a/src/libtomahawk/network/Connection.cpp +++ b/src/libtomahawk/network/Connection.cpp @@ -400,7 +400,7 @@ Connection::doSetup() { Q_D( Connection ); - tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread(); + tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread() << d->id; /* New connections can be created from other thread contexts, such as when AudioEngine calls getIODevice.. - we need to ensure that connections @@ -414,39 +414,49 @@ Connection::doSetup() moveToThread( d->servent->thread() ); } - //stats timer calculates BW used by this connection - d->statstimer = new QTimer; - d->statstimer->moveToThread( this->thread() ); - d->statstimer->setInterval( 1000 ); - connect( d->statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) ); - d->statstimer->start(); - d->statstimer_mark.start(); - - d->sock->moveToThread( thread() ); - - connect( d->sock.data(), SIGNAL( bytesWritten( qint64 ) ), - SLOT( bytesWritten( qint64 ) ), Qt::QueuedConnection ); - - connect( d->sock.data(), SIGNAL( disconnected() ), - SLOT( socketDisconnected() ), Qt::QueuedConnection ); - - connect( d->sock.data(), SIGNAL( error( QAbstractSocket::SocketError ) ), - SLOT( socketDisconnectedError( QAbstractSocket::SocketError ) ), Qt::QueuedConnection ); - - connect( d->sock.data(), SIGNAL( readyRead() ), - SLOT( readyRead() ), Qt::QueuedConnection ); - - // if connection not authed/setup fast enough, kill it: - QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authCheckTimeout() ) ); - - if ( outbound() ) + if ( !d->setup ) { - Q_ASSERT( !d->firstmsg.isNull() ); - sendMsg( d->firstmsg ); + // We only want to setup this connection once + d->setup = true; + + //stats timer calculates BW used by this connection + d->statstimer = new QTimer; + d->statstimer->moveToThread( this->thread() ); + d->statstimer->setInterval( 1000 ); + connect( d->statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) ); + d->statstimer->start(); + d->statstimer_mark.start(); + + d->sock->moveToThread( thread() ); + + connect( d->sock.data(), SIGNAL( bytesWritten( qint64 ) ), + SLOT( bytesWritten( qint64 ) ), Qt::QueuedConnection ); + + connect( d->sock.data(), SIGNAL( disconnected() ), + SLOT( socketDisconnected() ), Qt::QueuedConnection ); + + connect( d->sock.data(), SIGNAL( error( QAbstractSocket::SocketError ) ), + SLOT( socketDisconnectedError( QAbstractSocket::SocketError ) ), Qt::QueuedConnection ); + + connect( d->sock.data(), SIGNAL( readyRead() ), + SLOT( readyRead() ), Qt::QueuedConnection ); + + // if connection not authed/setup fast enough, kill it: + QTimer::singleShot( AUTH_TIMEOUT, this, SLOT( authCheckTimeout() ) ); + + if ( outbound() ) + { + Q_ASSERT( !d->firstmsg.isNull() ); + sendMsg( d->firstmsg ); + } + else + { + sendMsg( Msg::factory( PROTOVER, Msg::SETUP ) ); + } } else { - sendMsg( Msg::factory( PROTOVER, Msg::SETUP ) ); + tLog() << Q_FUNC_INFO << QThread::currentThread() << d->id << "Duplicate doSetup call"; } // call readyRead incase we missed the signal in between the servent disconnecting and us diff --git a/src/libtomahawk/network/Connection_p.h b/src/libtomahawk/network/Connection_p.h index 6e0d519fa..8baccaace 100644 --- a/src/libtomahawk/network/Connection_p.h +++ b/src/libtomahawk/network/Connection_p.h @@ -41,6 +41,7 @@ public: , peer_disconnected( false ) , ready( false ) , onceonly( true ) + , setup( false ) , tx_bytes( 0 ) , tx_bytes_requested( 0 ) , rx_bytes( 0 ) @@ -66,6 +67,7 @@ private: bool outbound; bool ready; bool onceonly; + bool setup; qint64 tx_bytes; qint64 tx_bytes_requested; qint64 rx_bytes;