1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Move peerport and msg into ConnectionPrivate

This commit is contained in:
Uwe L. Korn
2013-06-15 21:04:46 +02:00
parent ce11d3aec3
commit b5cce70b4d
3 changed files with 40 additions and 25 deletions

View File

@@ -34,7 +34,6 @@
Connection::Connection( Servent* parent ) Connection::Connection( Servent* parent )
: QObject() : QObject()
, m_sock( 0 ) , m_sock( 0 )
, m_peerport( 0 )
, m_servent( parent ) , m_servent( parent )
, m_ready( false ) , m_ready( false )
, m_onceonly( true ) , m_onceonly( true )
@@ -99,7 +98,9 @@ Connection::setFirstMessage( const QVariant& m )
void void
Connection::setFirstMessage( msg_ptr m ) Connection::setFirstMessage( msg_ptr m )
{ {
m_firstmsg = m; Q_D( Connection );
d->firstmsg = m;
//qDebug() << id() << " first msg set to " << QString::fromAscii(m_firstmsg->payload()) //qDebug() << id() << " first msg set to " << QString::fromAscii(m_firstmsg->payload())
// << "msg len:" << m_firstmsg->length() ; // << "msg len:" << m_firstmsg->length() ;
} }
@@ -107,7 +108,9 @@ Connection::setFirstMessage( msg_ptr m )
msg_ptr msg_ptr
Connection::firstMessage() const Connection::firstMessage() const
{ {
return m_firstmsg; Q_D( const Connection );
return d->firstmsg;
} }
const QPointer<QTcpSocket>& const QPointer<QTcpSocket>&
@@ -137,13 +140,17 @@ Connection::servent() const
int int
Connection::peerPort() const Connection::peerPort() const
{ {
return m_peerport; Q_D( const Connection );
return d->peerport;
} }
void void
Connection::setPeerPort(int p) Connection::setPeerPort(int p)
{ {
m_peerport = p; Q_D( Connection );
d->peerport = p;
} }
@@ -363,6 +370,8 @@ Connection::authCheckTimeout()
void void
Connection::doSetup() Connection::doSetup()
{ {
Q_D( Connection );
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << thread();
/* /*
New connections can be created from other thread contexts, such as New connections can be created from other thread contexts, such as
@@ -404,8 +413,8 @@ Connection::doSetup()
if ( outbound() ) if ( outbound() )
{ {
Q_ASSERT( !m_firstmsg.isNull() ); Q_ASSERT( !d->firstmsg.isNull() );
sendMsg( m_firstmsg ); sendMsg( d->firstmsg );
} }
else else
{ {
@@ -489,8 +498,9 @@ void
Connection::readyRead() Connection::readyRead()
{ {
// qDebug() << "readyRead, bytesavail:" << m_sock->bytesAvailable(); // qDebug() << "readyRead, bytesavail:" << m_sock->bytesAvailable();
Q_D( Connection );
if ( m_msg.isNull() ) if ( d->msg.isNull() )
{ {
if ( m_sock->bytesAvailable() < Msg::headerSize() ) if ( m_sock->bytesAvailable() < Msg::headerSize() )
return; return;
@@ -503,22 +513,22 @@ Connection::readyRead()
return; return;
} }
m_msg = Msg::begin( (char*) &msgheader ); d->msg = Msg::begin( (char*) &msgheader );
d_func()->rx_bytes += Msg::headerSize(); d->rx_bytes += Msg::headerSize();
} }
if ( m_sock->bytesAvailable() < m_msg->length() ) if ( m_sock->bytesAvailable() < d->msg->length() )
return; return;
QByteArray ba = m_sock->read( m_msg->length() ); QByteArray ba = m_sock->read( d->msg->length() );
if ( ba.length() != (qint32)m_msg->length() ) if ( ba.length() != (qint32)d->msg->length() )
{ {
tDebug() << "Failed to read full msg payload"; tDebug() << "Failed to read full msg payload";
this->markAsFailed(); this->markAsFailed();
return; return;
} }
m_msg->fill( ba ); d->msg->fill( ba );
d_func()->rx_bytes += ba.length(); d->rx_bytes += ba.length();
handleReadMsg(); // process m_msg and clear() it handleReadMsg(); // process m_msg and clear() it
@@ -533,9 +543,11 @@ Connection::readyRead()
void void
Connection::handleReadMsg() Connection::handleReadMsg()
{ {
Q_D( Connection );
if ( outbound() == false && if ( outbound() == false &&
m_msg->is( Msg::SETUP ) && d->msg->is( Msg::SETUP ) &&
m_msg->payload() == "ok" ) d->msg->payload() == "ok" )
{ {
m_ready = true; m_ready = true;
tDebug( LOGVERBOSE ) << "Connection" << id() << "READY"; tDebug( LOGVERBOSE ) << "Connection" << id() << "READY";
@@ -544,9 +556,9 @@ Connection::handleReadMsg()
} }
else if ( !m_ready && else if ( !m_ready &&
outbound() && outbound() &&
m_msg->is( Msg::SETUP ) ) d->msg->is( Msg::SETUP ) )
{ {
if ( m_msg->payload() == PROTOVER ) if ( d->msg->payload() == PROTOVER )
{ {
sendMsg( Msg::factory( "ok", Msg::SETUP ) ); sendMsg( Msg::factory( "ok", Msg::SETUP ) );
m_ready = true; m_ready = true;
@@ -562,17 +574,19 @@ Connection::handleReadMsg()
} }
else else
{ {
d_func()->msgprocessor_in.append( m_msg ); d->msgprocessor_in.append( d->msg );
} }
m_msg.clear(); d->msg.clear();
} }
void void
Connection::sendMsg( QVariant j ) Connection::sendMsg( QVariant j )
{ {
if ( d_func()->do_shutdown ) Q_D( Connection );
if ( d->do_shutdown )
return; return;
QJson::Serializer serializer; QJson::Serializer serializer;

View File

@@ -122,11 +122,8 @@ private slots:
protected: protected:
QPointer<QTcpSocket> m_sock; QPointer<QTcpSocket> m_sock;
int m_peerport;
msg_ptr m_msg;
Servent* m_servent; Servent* m_servent;
bool m_outbound, m_ready, m_onceonly; bool m_outbound, m_ready, m_onceonly;
msg_ptr m_firstmsg;
private: private:
Q_DECLARE_PRIVATE( Connection ) Q_DECLARE_PRIVATE( Connection )

View File

@@ -36,6 +36,7 @@ public:
, do_shutdown( false ) , do_shutdown( false )
, actually_shutting_down( false ) , actually_shutting_down( false )
, peer_disconnected( false ) , peer_disconnected( false )
, peerport( 0 )
, tx_bytes( 0 ) , tx_bytes( 0 )
, tx_bytes_requested( 0 ) , tx_bytes_requested( 0 )
, rx_bytes( 0 ) , rx_bytes( 0 )
@@ -61,6 +62,9 @@ private:
QString id; QString id;
QString name; QString name;
QString nodeid; QString nodeid;
msg_ptr msg;
msg_ptr firstmsg;
int peerport;
QTimer* statstimer; QTimer* statstimer;
QTime statstimer_mark; QTime statstimer_mark;