app level keepalive (new ping message) added
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 5 Aug 2012 05:37:22 +0000 (07:37 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 5 Aug 2012 05:37:22 +0000 (07:37 +0200)
web/Obj/sac-a-push.phh
web/Obj/user.phh
web/briskin5/index_wr.php
web/commons.js
web/index_wr.php

index bc0ea87..4a325da 100644 (file)
@@ -404,10 +404,18 @@ class Sac_a_push {
                 if (isset($this->s2u[intval($sock)])) {
                     $user = $this->s2u[intval($sock)];
                     $response = $user->rd_cache_get();
+                    if (($this->curtime - $user->lacc) <= (EXPIRE_TIME_RD / 2)) {
+                        $user->ping_req = FALSE;
+                    }
                     if ($response == "") {
                         $content = "";
                         $user->stream_main($content, $get, $post, $cookie);
-                        
+                        printf("[%s] [%d] [%d]\n", $user->name, $user->lacc, $this->curtime);
+                        if ($content == "" && $user->ping_req == FALSE 
+                            && (($this->curtime - $user->lacc) > (EXPIRE_TIME_RD / 2))) {
+                            $content = $user->stream_ping();
+                            $user->ping_req = TRUE;
+                        }
                         if ($content == "" && $user->rd_kalive_is_expired($this->curtime)) {
                             $content = $user->stream_keepalive();
                         }
index e94b4aa..b13f56e 100644 (file)
@@ -941,6 +941,15 @@ push(null);
 // -->
 </script>", $this->rd_scristp++));
     
+}
+
+function stream_ping()
+{
+    return (sprintf("<script id='hs%d' type='text/javascript'><!--
+push(\"act_ping();\");
+// -->
+</script>", $this->rd_scristp++));
+    
 }
 
     static function base_get()
index d865972..fbc37c5 100644 (file)
@@ -42,6 +42,7 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie)
 {
     GLOBAL $G_base, $G_dbasetype;
 
+    $curtime = time();
     if ($bri == NULL) {
         return FALSE;
     }
@@ -73,7 +74,10 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie)
     log_wr('POSTSPLIT: '.$argz[0].'  user->stat: ['.$user->stat.']');
     log_wr($user->step, 'bin::index_wr.php: after get_user()');
     
-    if (false && $argz[0] == 'shutdown') {
+    if ($argz[0] == 'ping') {
+        $user->lacc = $curtime;
+    }
+    else if (false && $argz[0] == 'shutdown') {
         log_auth($user_cur->sess, "Shutdown session. delegate to room gc the autologout");
         
         log_rd2("bin5/index_wr.php: AUTO LOGOUT.");
@@ -481,7 +485,6 @@ function bin5_index_wr_main(&$bri, $remote_addr, $get, $post, $cookie)
                         $pt_cur = calculate_points(&$table);
                         
                         $plist = "$table->table_token|$user->table_orig|$table->player_n";
-                        $curtime = time();
                         $ucodes = array();
                         for ($i = 0 ; $i < BIN5_PLAYERS_N ; $i++) {
                             $user_cur = &$bri->user[$table->player[$i]];
index 94de832..f0ea078 100644 (file)
@@ -329,6 +329,11 @@ function act_chatt(value)
 }
 
 /* Stat: ROOM */
+function act_ping()
+{
+    send_mesg("ping");
+}
+
 function act_sitdown(table)
 {
     send_mesg("sitdown|"+table);
index 99213b7..6995a18 100644 (file)
@@ -199,7 +199,10 @@ function index_wr_main(&$room, $remote_addr, $get, $post, $cookie)
 
     log_wr($user->step, 'index_wr.php: after get_user()');
 
-    if ($argz[0] == 'shutdown') {
+    if ($argz[0] == 'ping') {
+        $user->lacc = $curtime;
+    }
+    else if ($argz[0] == 'shutdown') {
         log_auth($user->sess, "Shutdown session.");
 
         $user->reset();