mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Use internal PING mechanism in Connection class instead of relying on TCP KEEPALIVE.
This commit is contained in:
@@ -30,6 +30,7 @@ class Msg
|
|||||||
public:
|
public:
|
||||||
enum Flag
|
enum Flag
|
||||||
{
|
{
|
||||||
|
PING = 0,
|
||||||
RAW = 1,
|
RAW = 1,
|
||||||
JSON = 2,
|
JSON = 2,
|
||||||
FRAGMENT = 4,
|
FRAGMENT = 4,
|
||||||
|
@@ -60,6 +60,8 @@ 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;
|
||||||
|
|
||||||
|
if ( !msg->is( Msg::PING ) )
|
||||||
emit ready( m );
|
emit ready( m );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include "servent.h"
|
#include "servent.h"
|
||||||
|
|
||||||
#define PROTOVER "2" // must match remote peer, or we can't talk.
|
#define PROTOVER "3" // must match remote peer, or we can't talk.
|
||||||
|
|
||||||
|
|
||||||
Connection::Connection( Servent* parent )
|
Connection::Connection( Servent* parent )
|
||||||
@@ -25,6 +25,7 @@ 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 )
|
||||||
@@ -57,6 +58,8 @@ Connection::~Connection()
|
|||||||
{
|
{
|
||||||
qDebug() << "no valid sock to delete";
|
qDebug() << "no valid sock to delete";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete m_pingtimer;
|
||||||
delete m_statstimer;
|
delete m_statstimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,19 +211,16 @@ Connection::doSetup()
|
|||||||
//stats timer calculates BW used by this connection
|
//stats timer calculates BW used by this connection
|
||||||
m_statstimer = new QTimer;
|
m_statstimer = new QTimer;
|
||||||
m_statstimer->moveToThread( this->thread() );
|
m_statstimer->moveToThread( this->thread() );
|
||||||
m_statstimer->setInterval(1000);
|
m_statstimer->setInterval( 1000 );
|
||||||
connect( m_statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) );
|
connect( m_statstimer, SIGNAL( timeout() ), SLOT( calcStats() ) );
|
||||||
m_statstimer->start();
|
m_statstimer->start();
|
||||||
m_statstimer_mark.start();
|
m_statstimer_mark.start();
|
||||||
|
|
||||||
m_sock->setSocketOption( QAbstractSocket::KeepAliveOption, 1 );
|
m_pingtimer = new QTimer;
|
||||||
int sockID = m_sock.data()->socketDescriptor();
|
m_pingtimer->moveToThread( this->thread() );
|
||||||
int idle = 30;
|
m_pingtimer->setInterval( 5000 );
|
||||||
int intvl = 5;
|
connect( m_pingtimer, SIGNAL( timeout() ), SLOT( onPingTimer() ) );
|
||||||
int cnt = 3;
|
m_pingtimer->start();
|
||||||
setsockopt( sockID, SOL_TCP, TCP_KEEPIDLE, &idle, sizeof( idle ) );
|
|
||||||
setsockopt( sockID, SOL_TCP, TCP_KEEPINTVL, &intvl, sizeof( intvl ) );
|
|
||||||
setsockopt( sockID, SOL_TCP, TCP_KEEPCNT, &cnt, sizeof( cnt ) );
|
|
||||||
|
|
||||||
m_sock->moveToThread( thread() );
|
m_sock->moveToThread( thread() );
|
||||||
|
|
||||||
@@ -462,3 +462,11 @@ 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,6 +99,7 @@ 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;
|
||||||
@@ -118,6 +119,8 @@ 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;
|
||||||
|
Reference in New Issue
Block a user