server-side ping management fixed
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sun, 7 Oct 2012 09:02:36 +0000 (11:02 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Sun, 7 Oct 2012 09:02:36 +0000 (11:02 +0200)
web/Obj/brisk.phh
web/Obj/sac-a-push.phh
web/Obj/user.phh
web/index_wr.php

index 41524d2..e7ff714 100644 (file)
@@ -50,6 +50,8 @@ define('CHAT_ENABLED', TRUE);
 define('SESS_LEN', 13);
 define('STREAM_TIMEOUT', 60);
 /* FIXME: move to sac-a-push .phh */
+/* TIME_RD define the server-side timeout, after half of it a ping request
+   is sent to client, after this time the client is log out */
 define('EXPIRE_TIME_RD', 180);
 define('EXPIRE_TIME_SMAMMA', 360);
 define('EXPIRE_TIME_WAG', 10);
index c9220a1..fd0368b 100644 (file)
@@ -421,13 +421,12 @@ class Sac_a_push {
                         $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 
+                        if ($user->ping_req == FALSE
                             && (($this->curtime - $user->lacc) > (EXPIRE_TIME_RD / 2))) {
-                            // $content = $user->stream_keepalive(TRUE);
-                            $content += $user->stream_keepalive(TRUE);
+                            $content .= $user->stream_keepalive(TRUE);
                             $user->ping_req = TRUE;
                         }
-                        if ($content == "" && $user->rd_kalive_is_expired($this->curtime)) {
+                        else if ($content == "" && $user->rd_kalive_is_expired($this->curtime)) {
                             $content = $user->stream_keepalive(FALSE);
                         }
                         if ($content != "") {
index 8beb49b..a6f1b90 100644 (file)
@@ -946,11 +946,12 @@ push(\"%s\");
 
 function stream_keepalive($with_ping)
 {
-    return (sprintf("<script id='hs%d' type='text/javascript'><!--
+    $ret =  (sprintf("<script id='hs%d' type='text/javascript'><!--
 push(%s);
 // -->
 </script>", $this->rd_scristp++, ($with_ping ? "\"act_ping();\"" : "null")));
-    
+
+    return ($ret);
 }
 
 static function base_get()
index 6995a18..727f62b 100644 (file)
@@ -197,9 +197,8 @@ function index_wr_main(&$room, $remote_addr, $get, $post, $cookie)
 
     log_wr('POSTSPLIT: '.$argz[0]);
 
-    log_wr($user->step, 'index_wr.php: after get_user()');
-
     if ($argz[0] == 'ping') {
+        log_wr("PING RECEIVED, LACC UPDATED\n");
         $user->lacc = $curtime;
     }
     else if ($argz[0] == 'shutdown') {