1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 19:30:21 +02:00

* Move PING command to ControlConnection.

This commit is contained in:
Christian Muehlhaeuser
2010-11-25 05:04:26 +01:00
parent 28b543a5c5
commit ec7995dc42
6 changed files with 36 additions and 27 deletions

View File

@@ -30,14 +30,13 @@ class Msg
public:
enum Flag
{
PING = 0,
RAW = 1,
JSON = 2,
FRAGMENT = 4,
COMPRESSED = 8,
DBOP = 16,
UNUSED_FLAG_6 = 32,
UNUSED_FLAG_7 = 64,
PING = 32,
PONG = 64,
SETUP = 128 // used to handshake/auth the connection prior to handing over to Connection subclass
};

View File

@@ -60,9 +60,7 @@ void MsgProcessor::handleProcessedMsg( msg_ptr msg )
msg_ptr m = m_msgs.takeFirst();
m_msg_ready.remove( m.data() );
//qDebug() << Q_FUNC_INFO << "totmsgsize:" << m_totmsgsize;
if ( !msg->is( Msg::PING ) )
emit ready( m );
emit ready( m );
}
else
{

View File

@@ -25,7 +25,6 @@ Connection::Connection( Servent* parent )
, m_tx_bytes_requested( 0 )
, m_rx_bytes( 0 )
, m_id( "Connection()" )
, m_pingtimer( 0 )
, m_statstimer( 0 )
, m_stats_tx_bytes_per_sec( 0 )
, m_stats_rx_bytes_per_sec( 0 )
@@ -59,7 +58,6 @@ Connection::~Connection()
qDebug() << "no valid sock to delete";
}
delete m_pingtimer;
delete m_statstimer;
}
@@ -216,12 +214,6 @@ Connection::doSetup()
m_statstimer->start();
m_statstimer_mark.start();
m_pingtimer = new QTimer;
m_pingtimer->moveToThread( this->thread() );
m_pingtimer->setInterval( 5000 );
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
m_pingtimer->start();
m_sock->moveToThread( thread() );
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
@@ -407,7 +399,7 @@ Connection::sendMsg( msg_ptr msg )
if( m_do_shutdown )
{
qDebug() << Q_FUNC_INFO << "SHUTTING DOWN, NOT SENDING msg flags:"
<< (int)msg->flags() << "length:" << msg->length();
<< (int)msg->flags() << "length:" << msg->length() << id();
return;
}
@@ -426,7 +418,7 @@ Connection::sendMsg_now( msg_ptr msg )
if( m_sock.isNull() || !m_sock->isOpen() || !m_sock->isWritable() )
{
qDebug() << "***** Socket problem, whilst in sendMsg(). Cleaning up. *****";
shutdown( true );
shutdown( false );
return;
}
@@ -462,11 +454,3 @@ Connection::calcStats()
emit statsTick( m_stats_tx_bytes_per_sec, m_stats_rx_bytes_per_sec );
}
void
Connection::onPingTimer()
{
qDebug() << Q_FUNC_INFO;
sendMsg( Msg::factory( QByteArray(), Msg::PING ) );
}

View File

@@ -99,7 +99,6 @@ private slots:
void authCheckTimeout();
void bytesWritten( qint64 );
void calcStats();
void onPingTimer();
protected:
QPointer<QTcpSocket> m_sock;
@@ -119,8 +118,6 @@ private:
qint64 m_rx_bytes;
QString m_id;
QTimer* m_pingtimer;
QTimer* m_statstimer;
QTime m_statstimer_mark;
qint64 m_stats_tx_bytes_per_sec, m_stats_rx_bytes_per_sec;

View File

@@ -14,6 +14,7 @@ ControlConnection::ControlConnection( Servent* parent )
: Connection( parent )
, m_dbsyncconn( 0 )
, m_registered( false )
, m_pingtimer( 0 )
{
qDebug() << "CTOR controlconnection";
setId("ControlConnection()");
@@ -29,6 +30,8 @@ ControlConnection::ControlConnection( Servent* parent )
ControlConnection::~ControlConnection()
{
qDebug() << "DTOR controlconnection";
delete m_pingtimer;
m_servent->unregisterControlConnection(this);
if( m_dbsyncconn ) m_dbsyncconn->deleteLater();
}
@@ -71,6 +74,11 @@ ControlConnection::setup()
SLOT( registerSource() ), Qt::QueuedConnection );
m_source->doDBSync();
m_pingtimer = new QTimer;
m_pingtimer->setInterval( 5000 );
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
m_pingtimer->start();
}
@@ -169,6 +177,17 @@ ControlConnection::handleMsg( msg_ptr msg )
qDebug() << id() << "got msg:" << QString::fromAscii( msg->payload() );
}
qDebug() << msg->flags();
if ( msg->is( Msg::PING ) )
{
qDebug() << "Received Connection PING, sending PONG.";
sendMsg( Msg::factory( QByteArray(), Msg::PONG ) );
}
else if ( msg->is( Msg::PONG ) )
{
qDebug() << "Received Connection PONG, nice.";
}
// All control connection msgs are JSON
if( !msg->is( Msg::JSON ) )
{
@@ -207,3 +226,12 @@ ControlConnection::handleMsg( msg_ptr msg )
qDebug() << id() << "Invalid msg:" << QString::fromAscii(msg->payload());
}
void
ControlConnection::onPingTimer()
{
qDebug() << Q_FUNC_INFO;
sendMsg( Msg::factory( QByteArray(), Msg::PING ) );
}

View File

@@ -37,6 +37,7 @@ signals:
private slots:
void dbSyncConnFinished( QObject* c );
void registerSource();
void onPingTimer();
private:
void setupDbSyncConnection( bool ondemand = false );
@@ -46,6 +47,8 @@ private:
QString m_dbconnkey;
bool m_registered;
QTimer* m_pingtimer;
};
#endif // CONTROLCONNECTION_H