mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-12 00:54:20 +02:00
Only setup a Connection once
This commit is contained in:
committed by
Michael Zanetti
parent
cf93741079
commit
ff8e905599
@@ -400,7 +400,7 @@ Connection::doSetup()
|
|||||||
{
|
{
|
||||||
Q_D( Connection );
|
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
|
New connections can be created from other thread contexts, such as
|
||||||
when AudioEngine calls getIODevice.. - we need to ensure that connections
|
when AudioEngine calls getIODevice.. - we need to ensure that connections
|
||||||
@@ -414,39 +414,49 @@ Connection::doSetup()
|
|||||||
moveToThread( d->servent->thread() );
|
moveToThread( d->servent->thread() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//stats timer calculates BW used by this connection
|
if ( !d->setup )
|
||||||
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() );
|
// We only want to setup this connection once
|
||||||
sendMsg( d->firstmsg );
|
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
|
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
|
// call readyRead incase we missed the signal in between the servent disconnecting and us
|
||||||
|
@@ -41,6 +41,7 @@ public:
|
|||||||
, peer_disconnected( false )
|
, peer_disconnected( false )
|
||||||
, ready( false )
|
, ready( false )
|
||||||
, onceonly( true )
|
, onceonly( true )
|
||||||
|
, setup( false )
|
||||||
, tx_bytes( 0 )
|
, tx_bytes( 0 )
|
||||||
, tx_bytes_requested( 0 )
|
, tx_bytes_requested( 0 )
|
||||||
, rx_bytes( 0 )
|
, rx_bytes( 0 )
|
||||||
@@ -66,6 +67,7 @@ private:
|
|||||||
bool outbound;
|
bool outbound;
|
||||||
bool ready;
|
bool ready;
|
||||||
bool onceonly;
|
bool onceonly;
|
||||||
|
bool setup;
|
||||||
qint64 tx_bytes;
|
qint64 tx_bytes;
|
||||||
qint64 tx_bytes_requested;
|
qint64 tx_bytes_requested;
|
||||||
qint64 rx_bytes;
|
qint64 rx_bytes;
|
||||||
|
Reference in New Issue
Block a user