mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
* Move PING command to ControlConnection.
This commit is contained in:
@@ -30,14 +30,13 @@ class Msg
|
|||||||
public:
|
public:
|
||||||
enum Flag
|
enum Flag
|
||||||
{
|
{
|
||||||
PING = 0,
|
|
||||||
RAW = 1,
|
RAW = 1,
|
||||||
JSON = 2,
|
JSON = 2,
|
||||||
FRAGMENT = 4,
|
FRAGMENT = 4,
|
||||||
COMPRESSED = 8,
|
COMPRESSED = 8,
|
||||||
DBOP = 16,
|
DBOP = 16,
|
||||||
UNUSED_FLAG_6 = 32,
|
PING = 32,
|
||||||
UNUSED_FLAG_7 = 64,
|
PONG = 64,
|
||||||
SETUP = 128 // used to handshake/auth the connection prior to handing over to Connection subclass
|
SETUP = 128 // used to handshake/auth the connection prior to handing over to Connection subclass
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -60,9 +60,7 @@ void MsgProcessor::handleProcessedMsg( msg_ptr msg )
|
|||||||
msg_ptr m = m_msgs.takeFirst();
|
msg_ptr m = m_msgs.takeFirst();
|
||||||
m_msg_ready.remove( m.data() );
|
m_msg_ready.remove( m.data() );
|
||||||
//qDebug() << Q_FUNC_INFO << "totmsgsize:" << m_totmsgsize;
|
//qDebug() << Q_FUNC_INFO << "totmsgsize:" << m_totmsgsize;
|
||||||
|
emit ready( m );
|
||||||
if ( !msg->is( Msg::PING ) )
|
|
||||||
emit ready( m );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -25,7 +25,6 @@ Connection::Connection( Servent* parent )
|
|||||||
, m_tx_bytes_requested( 0 )
|
, m_tx_bytes_requested( 0 )
|
||||||
, m_rx_bytes( 0 )
|
, m_rx_bytes( 0 )
|
||||||
, m_id( "Connection()" )
|
, m_id( "Connection()" )
|
||||||
, m_pingtimer( 0 )
|
|
||||||
, m_statstimer( 0 )
|
, m_statstimer( 0 )
|
||||||
, m_stats_tx_bytes_per_sec( 0 )
|
, m_stats_tx_bytes_per_sec( 0 )
|
||||||
, m_stats_rx_bytes_per_sec( 0 )
|
, m_stats_rx_bytes_per_sec( 0 )
|
||||||
@@ -59,7 +58,6 @@ Connection::~Connection()
|
|||||||
qDebug() << "no valid sock to delete";
|
qDebug() << "no valid sock to delete";
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_pingtimer;
|
|
||||||
delete m_statstimer;
|
delete m_statstimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,12 +214,6 @@ Connection::doSetup()
|
|||||||
m_statstimer->start();
|
m_statstimer->start();
|
||||||
m_statstimer_mark.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() );
|
m_sock->moveToThread( thread() );
|
||||||
|
|
||||||
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
||||||
@@ -407,7 +399,7 @@ Connection::sendMsg( msg_ptr msg )
|
|||||||
if( m_do_shutdown )
|
if( m_do_shutdown )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "SHUTTING DOWN, NOT SENDING msg flags:"
|
qDebug() << Q_FUNC_INFO << "SHUTTING DOWN, NOT SENDING msg flags:"
|
||||||
<< (int)msg->flags() << "length:" << msg->length();
|
<< (int)msg->flags() << "length:" << msg->length() << id();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +418,7 @@ Connection::sendMsg_now( msg_ptr msg )
|
|||||||
if( m_sock.isNull() || !m_sock->isOpen() || !m_sock->isWritable() )
|
if( m_sock.isNull() || !m_sock->isOpen() || !m_sock->isWritable() )
|
||||||
{
|
{
|
||||||
qDebug() << "***** Socket problem, whilst in sendMsg(). Cleaning up. *****";
|
qDebug() << "***** Socket problem, whilst in sendMsg(). Cleaning up. *****";
|
||||||
shutdown( true );
|
shutdown( false );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,11 +454,3 @@ Connection::calcStats()
|
|||||||
|
|
||||||
emit statsTick( m_stats_tx_bytes_per_sec, m_stats_rx_bytes_per_sec );
|
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 ) );
|
|
||||||
}
|
|
||||||
|
@@ -99,7 +99,6 @@ private slots:
|
|||||||
void authCheckTimeout();
|
void authCheckTimeout();
|
||||||
void bytesWritten( qint64 );
|
void bytesWritten( qint64 );
|
||||||
void calcStats();
|
void calcStats();
|
||||||
void onPingTimer();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QPointer<QTcpSocket> m_sock;
|
QPointer<QTcpSocket> m_sock;
|
||||||
@@ -119,8 +118,6 @@ private:
|
|||||||
qint64 m_rx_bytes;
|
qint64 m_rx_bytes;
|
||||||
QString m_id;
|
QString m_id;
|
||||||
|
|
||||||
QTimer* m_pingtimer;
|
|
||||||
|
|
||||||
QTimer* m_statstimer;
|
QTimer* m_statstimer;
|
||||||
QTime m_statstimer_mark;
|
QTime m_statstimer_mark;
|
||||||
qint64 m_stats_tx_bytes_per_sec, m_stats_rx_bytes_per_sec;
|
qint64 m_stats_tx_bytes_per_sec, m_stats_rx_bytes_per_sec;
|
||||||
|
@@ -14,6 +14,7 @@ ControlConnection::ControlConnection( Servent* parent )
|
|||||||
: Connection( parent )
|
: Connection( parent )
|
||||||
, m_dbsyncconn( 0 )
|
, m_dbsyncconn( 0 )
|
||||||
, m_registered( false )
|
, m_registered( false )
|
||||||
|
, m_pingtimer( 0 )
|
||||||
{
|
{
|
||||||
qDebug() << "CTOR controlconnection";
|
qDebug() << "CTOR controlconnection";
|
||||||
setId("ControlConnection()");
|
setId("ControlConnection()");
|
||||||
@@ -29,6 +30,8 @@ ControlConnection::ControlConnection( Servent* parent )
|
|||||||
ControlConnection::~ControlConnection()
|
ControlConnection::~ControlConnection()
|
||||||
{
|
{
|
||||||
qDebug() << "DTOR controlconnection";
|
qDebug() << "DTOR controlconnection";
|
||||||
|
|
||||||
|
delete m_pingtimer;
|
||||||
m_servent->unregisterControlConnection(this);
|
m_servent->unregisterControlConnection(this);
|
||||||
if( m_dbsyncconn ) m_dbsyncconn->deleteLater();
|
if( m_dbsyncconn ) m_dbsyncconn->deleteLater();
|
||||||
}
|
}
|
||||||
@@ -71,6 +74,11 @@ ControlConnection::setup()
|
|||||||
SLOT( registerSource() ), Qt::QueuedConnection );
|
SLOT( registerSource() ), Qt::QueuedConnection );
|
||||||
|
|
||||||
m_source->doDBSync();
|
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() << 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
|
// All control connection msgs are JSON
|
||||||
if( !msg->is( Msg::JSON ) )
|
if( !msg->is( Msg::JSON ) )
|
||||||
{
|
{
|
||||||
@@ -207,3 +226,12 @@ ControlConnection::handleMsg( msg_ptr msg )
|
|||||||
|
|
||||||
qDebug() << id() << "Invalid msg:" << QString::fromAscii(msg->payload());
|
qDebug() << id() << "Invalid msg:" << QString::fromAscii(msg->payload());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ControlConnection::onPingTimer()
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
sendMsg( Msg::factory( QByteArray(), Msg::PING ) );
|
||||||
|
}
|
||||||
|
@@ -37,6 +37,7 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void dbSyncConnFinished( QObject* c );
|
void dbSyncConnFinished( QObject* c );
|
||||||
void registerSource();
|
void registerSource();
|
||||||
|
void onPingTimer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupDbSyncConnection( bool ondemand = false );
|
void setupDbSyncConnection( bool ondemand = false );
|
||||||
@@ -46,6 +47,8 @@ private:
|
|||||||
|
|
||||||
QString m_dbconnkey;
|
QString m_dbconnkey;
|
||||||
bool m_registered;
|
bool m_registered;
|
||||||
|
|
||||||
|
QTimer* m_pingtimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTROLCONNECTION_H
|
#endif // CONTROLCONNECTION_H
|
||||||
|
Reference in New Issue
Block a user