-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I've worked on

http://jspoker.pokersource.info/ideas.html#[[reduce the ping%2Fpoll
noise]]

and produced the following patch as refrenced in

http://jspoker.pokersource.info/ideas.html#[[only send ping when no
packet sent during N seconds]]

Feel free to comment.

diff -r 1cbdd3509d63 jpoker/js/jquery.jpoker.js
- --- a/jpoker/js/jquery.jpoker.js    Wed Sep 24 15:32:25 2008 +0000
+++ b/jpoker/js/jquery.jpoker.js    Thu Sep 25 15:57:32 2008 +0200
@@ -580,6 +580,7 @@
                 // empty the incoming queue
                 this.queues = {};
                 this.delays = {};
+                this.sentTime = 0;
                 this.connectionState = 'disconnected';
             },
 
@@ -704,18 +705,21 @@
                         }
                     }
                 };
+                this.sentTime = jpoker.now();
                 this.ajax(args);
             },
 
             ping: function() {
- -                if(jQuery([$.ajax_queue]).queue('ajax').length <= 0) {
+                var delta = jpoker.now() - this.sentTime;
+                if(delta > this.pingFrequency) {
                     this.sendPacket({ type: 'PacketPing' });
+                    delta = 0;
                 }
                 this.clearTimeout(this.pingTimer);
                 var $this = this;
                 this.pingTimer = this.setTimeout(function() {
                         $this.ping();
- -                    }, this.pingFrequency);
+                    }, this.pingFrequency - delta);
             },
 
             pinging: function() { return this.pingTimer >= 0; },
diff -r 1cbdd3509d63 jpoker/js/test-jpoker.js
- --- a/jpoker/js/test-jpoker.js    Wed Sep 24 15:32:25 2008 +0000
+++ b/jpoker/js/test-jpoker.js    Thu Sep 25 15:57:32 2008 +0200
@@ -1560,6 +1560,34 @@
             });
     });
 
+test("jpoker.connection:ping frequency", function(){
+        expect(4);
+        //
+        // The next ping occurs N seconds after the last packet was sent
+        //
+        var clock = 10;
+        jpoker.now = function() { return clock++; };
+        var self = new jpoker.connection();
+        self.sendPacket = function() { equals(1,0,'sendPacket called'); }
+        sentTime = self.sentTime = jpoker.now();
+        self.setTimeout = function(fun, when) {
+            equals(when, self.pingFrequency - 1);
+        };
+        self.ping();
+        equals(sentTime, self.sentTime, 'sentTime');
+        //
+        // The next ping occurs after pingFrequency
+        //
+        clock = 200000;
+        self.sendPacket = function() { equals(12,12); }
+        self.sentTime = 0;
+        self.setTimeout = function(fun, when) {
+            equals(when, self.pingFrequency);
+        };
+        self.ping();
+        self.reset();
+    });
+
 test("jpoker.connection:sendPacket error 404", function(){
         expect(1);
         stop();
@@ -1609,8 +1637,8 @@
         ActiveXObject.defaults.timeout = false;
     });
 
- -test("jpoker.connection:sendPacket ", function(){
- -        expect(5);
+test("jpoker.connection:sendPacket", function(){
+        expect(7);
         var self = new jpoker.connection({
                 async: false,
                 mode: null
@@ -1645,8 +1673,10 @@
         var packet = {type: type};
 
         equals(self.connected(), false, "disconnected()");
+        equals(self.sentTime, 0, "sentTime default");
         self.sendPacket(packet);
 
+        equals(self.sentTime > 0, true, "sentTime updated");
         equals(handled[0], self);
         equals(handled[1], 0);
         equals(handled[2].type, type);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjbm8QACgkQ8dLMyEl6F23fNwCgjE75vfUlp9MmZgdNG21EzI1P
LjEAoKikuvneKOiN9R1EYtx4x5pagUUE
=q015
-----END PGP SIGNATURE-----

begin:vcard
fn:Loic Dachary
n:Dachary;Loic
org:pokersource
adr:;;12 bd Magenta;Paris;;75010;France
email;internet:[EMAIL PROTECTED]
title:Senior Developer
tel;work:+33 9 51 18 43 38
tel;cell:+33 6 64 03 29 07
x-mozilla-html:FALSE
url:http://dachary.org/
version:2.1
end:vcard

_______________________________________________
Pokersource-users mailing list
[email protected]
https://mail.gna.org/listinfo/pokersource-users

Reply via email to