modification to fix explorer bug.
[brisk.git] / web / Obj / sac-a-push.phh
index fd0368b..fa78539 100644 (file)
@@ -262,6 +262,23 @@ class Sac_a_push {
         array_push($this->pages_flush, $pgflush);
     }
 
+    function garbage_manager($force)
+    {
+        $this->app->garbage_manager($force);
+
+        foreach ($this->socks as $k => $sock) {
+            if ($this->s2u[intval($sock)]->sess == '') {
+                if ($this->s2u[intval($sock)]->rd_socket_get() != NULL) {
+                    $this->s2u[intval($sock)]->rd_socket_set(NULL);
+                }
+                unset($this->socks[intval($sock)]);
+                unset($this->s2u[intval($sock)]);
+                fclose($sock);
+                printf("CLOSE ON GARBAGE MANAGER\n");
+            }
+        }
+    }
+
     function run()
     {
         if ($this->main_loop) {
@@ -288,7 +305,7 @@ class Sac_a_push {
             }
             $write  = NULL;
             $except = NULL;
-            $num_changed_sockets = stream_select($read, $write, $except, 5, 0);
+            $num_changed_sockets = stream_select($read, $write, $except, 0, 100000);
         
             if ($num_changed_sockets == 0) {
                 printf(" no data in 5 secs ");
@@ -391,10 +408,8 @@ class Sac_a_push {
                     }
                 }
             }
-            
-
-            $this->app->garbage_manager(FALSE);
 
+            $this->garbage_manager(FALSE);
 
             /* manage unfinished pages */
             foreach ($this->pages_flush as $k => $pgflush) {
@@ -414,15 +429,19 @@ 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)) {
+                    $do_ping = FALSE;
+                    if (($this->curtime - $user->lacc) > (EXPIRE_TIME_RD / 3)) {
+                        $do_ping = TRUE;
+                    }
+                    else {
                         $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 ($user->ping_req == FALSE
-                            && (($this->curtime - $user->lacc) > (EXPIRE_TIME_RD / 2))) {
+                        if ($do_ping && $user->ping_req == FALSE) {
                             $content .= $user->stream_keepalive(TRUE);
                             $user->ping_req = TRUE;
                         }
@@ -436,7 +455,7 @@ class Sac_a_push {
                     
                     if ($response != "") {
                         // echo "SPIA: [".substr($response, 0, 60)."...]\n";
-                        echo "SPIA: [".$response."...]\n";
+                        echo "SPIA: [".$response."]\n";
                         $response_l = mb_strlen($response, "ASCII");
                         $wret = @fwrite($sock, $response);
                         if ($wret < $response_l) {
@@ -467,4 +486,4 @@ class Sac_a_push {
     }  // function run(...
 }
 
-?>
\ No newline at end of file
+?>