[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kopete-devel
Subject:    [Kopete-devel] kdenonbeta/kopete/protocols/msn
From:       Martijn Klingens <klingens () kde ! org>
Date:       2003-01-05 17:33:07
[Download RAW message or body]

CVS commit by mklingens: 

Send a 'list groups' (LSG) command as keepalive if there's no other activity
in 60 seconds. This might help people who get kicked off MSN very often if
there's little activity.

Thanks to Thomas Skarsvåg for pointing me to this idea, and for sending me
the piece of source code that amsn uses to do this.

CCMAIL: Thomas Skarsvåg <skarsva@online.no>

Kopete-devel: is this a candidate for backport to Kopete 0.5 branch?

CCMAIL: kopete-devel@kde.org


  M +23 -1     msnnotifysocket.cpp   1.62
  M +15 -2     msnnotifysocket.h   1.26
  M +1 -0      msnsocket.cpp   1.48
  M +6 -0      msnsocket.h   1.21


--- kdenonbeta/kopete/protocols/msn/msnnotifysocket.cpp  #1.61:1.62
@@ -44,4 +44,9 @@ MSNNotifySocket::MSNNotifySocket( MSNPro
         m_dispatchSocket = 0L;
         m_newstatus = MSNProtocol::NLN;
+
+        m_keepaliveTimer = new QTimer( this, "m_keepaliveTimer" );
+        QObject::connect( m_keepaliveTimer, SIGNAL( timeout() ), SLOT( slotSendKeepAlive() ) );
+
+        QObject::connect( this, SIGNAL( commandSent() ), SLOT( slotResetKeepAlive() ) );
 }
 
@@ -87,4 +92,6 @@ void MSNNotifySocket::disconnect()
                 sendCommand( "OUT", QString::null, false );
 
+        m_keepaliveTimer->stop();
+
         MSNAuthSocket::disconnect();
 }
@@ -531,5 +538,5 @@ void MSNNotifySocket::setStatus( int sta
 }
 
-void MSNNotifySocket::changePublicName( const QString &publicName  , const QString &handle)
+void MSNNotifySocket::changePublicName( const QString &publicName, const QString &handle )
 {
         if(handle.isNull())
@@ -584,4 +591,19 @@ void MSNNotifySocket::slotDispatchClosed
                 emit socketClosed(-1);
         }
+}
+
+void MSNNotifySocket::slotSendKeepAlive()
+{
+        // Send a dummy command to fake activity. This makes sure MSN doesn't
+        // disconnect you when the notify socket is idle.
+        sendCommand( "LSG", QString::null );
+}
+
+void MSNNotifySocket::slotResetKeepAlive()
+{
+        kdDebug() << "****** RESET KEEPALIVE!" << endl;
+        // Fire the timer every 60 seconds. QTimer will reset a running timer
+        // on a subsequent call if there has been activity again.
+        m_keepaliveTimer->start( 60000 );
 }
 

--- kdenonbeta/kopete/protocols/msn/msnnotifysocket.h  #1.25:1.26
@@ -103,4 +103,15 @@ private slots:
         void slotDispatchClosed();
 
+        /**
+         * Send a keepalive to the server to avoid idle connections to cause
+         * MSN closing the connection
+         */
+        void slotSendKeepAlive();
+
+        /**
+         * Reset the keepalive time after the socket has sent a command.
+         */
+        void slotResetKeepAlive();
+
 private:
         MSNProtocol *m_protocol;
@@ -125,4 +136,6 @@ private:
         QString m_sid;
         QString m_hotmailRequest;
+
+        QTimer *m_keepaliveTimer;
 };
 

--- kdenonbeta/kopete/protocols/msn/msnsocket.cpp  #1.47:1.48
@@ -418,4 +418,5 @@ void MSNSocket::slotReadyWrite()
                 m_socket->writeBlock( *it, (*it).length() );
                 m_sendQueue.remove( it );
+                emit( commandSent() );
 
                 // If the queue is empty again stop waiting for readyWrite signals

--- kdenonbeta/kopete/protocols/msn/msnsocket.h  #1.20:1.21
@@ -115,4 +115,10 @@ signals:
         void socketClosed( int );
 
+        /**
+         * The socket just sent a command from the queue. This signal is used in
+         * the notify socket to reset the keepalive timer.
+         */
+        void commandSent();
+
 protected:
         /**


_______________________________________________
Kopete-devel mailing list
Kopete-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/kopete-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic