stream_ping functionalities added to stream_keepalive function
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 4 Oct 2012 06:03:13 +0000 (08:03 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.com>
Thu, 4 Oct 2012 06:03:13 +0000 (08:03 +0200)
web/Obj/sac-a-push.phh
web/Obj/user.phh

index 70ae6bf..54929fa 100644 (file)
@@ -403,6 +403,12 @@ class Sac_a_push {
                 }
             }
             
+            /*
+               $response:                        raw stream data not sent
+               $content:                         html consistent data (<script bla bla>)
+               $user->stream_keepalive($w_ping)  ping srv->cli OR srv->cli + cli->srv if $w_ping == TRUE
+            */
+
             /* manage open streaming */
             foreach ($this->socks as $k => $sock) {
                 if (isset($this->s2u[intval($sock)])) {
@@ -417,11 +423,11 @@ class Sac_a_push {
                         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();
+                            $content = $user->stream_keepalive(TRUE);
                             $user->ping_req = TRUE;
                         }
                         if ($content == "" && $user->rd_kalive_is_expired($this->curtime)) {
-                            $content = $user->stream_keepalive();
+                            $content = $user->stream_keepalive(FALSE);
                         }
                         if ($content != "") {
                             $response = chunked_content($content);
index 761c9cc..8beb49b 100644 (file)
@@ -944,31 +944,22 @@ push(\"%s\");
     return TRUE;
 }
 
-function stream_keepalive()
+function stream_keepalive($with_ping)
 {
     return (sprintf("<script id='hs%d' type='text/javascript'><!--
-push(null);
+push(%s);
 // -->
-</script>", $this->rd_scristp++));
+</script>", $this->rd_scristp++, ($with_ping ? "\"act_ping();\"" : "null")));
     
 }
 
-function stream_ping()
+static function base_get()
 {
-    return (sprintf("<script id='hs%d' type='text/javascript'><!--
-push(\"act_ping();\");
-// -->
-</script>", $this->rd_scristp++));
-    
+    $c = get_called_class();
+    printf("CALLED_CLASS: [%s]\n", $c);
+    return $c::BASE;
 }
 
-    static function base_get()
-    {
-        $c = get_called_class();
-        printf("CALLED_CLASS: [%s]\n", $c);
-        return $c::BASE;
-    }
-
 } // end class User