from PageFlush to more generale PendingPage class
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 5 Feb 2013 17:05:35 +0000 (18:05 +0100)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Tue, 5 Feb 2013 17:05:35 +0000 (18:05 +0100)
web/Obj/brisk.phh
web/Obj/sac-a-push.phh
web/briskin5/Obj/briskin5.phh
web/spush/brisk-spush.phh

index 09ea77f..bd1edb8 100644 (file)
@@ -2215,7 +2215,7 @@ class Room
           $content = ob_get_contents();
           ob_end_clean();
 
-          $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+          $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
           return TRUE;
 
           break;
@@ -2225,7 +2225,7 @@ class Room
           $content = ob_get_contents();
           ob_end_clean();
           
-          $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+          $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
           return TRUE;
 
           break;
@@ -2238,7 +2238,7 @@ class Room
                   
                   $content = User::stream_fini($transp, $s_a_p->rndstr, TRUE);
 
-                  $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+                  $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
                   return TRUE;
 
                   break;
index b931340..d39740c 100644 (file)
@@ -121,7 +121,7 @@ function spu_process_info($stream_info, $method, &$header, &$get, &$post, &$cook
             }
             // GET params management
             $get_vars = explode('?', $req[1], 2);
-            $path =   $get_vars[0];
+            $path = $get_vars[0];
             if (count($get_vars) > 1) {
                 $a = explode('&', $get_vars[1]);
                 printf("A COUNT: [%s] %d\n", $a[0], count($a));
@@ -372,7 +372,7 @@ class Sac_a_push {
     var $unix_socket;
     var $socks;
     var $s2u;
-    var $pages_flush;
+    var $pending_pages;
 
     var $list;
     var $in;
@@ -425,7 +425,7 @@ class Sac_a_push {
         $thiz->debug = $debug;
         $thiz->socks = array();
         $thiz->s2u  = array();
-        $thiz->pages_flush = array();
+        $thiz->pending_pages = array();
 
         // create a couple of sockets for control management
         if (($sockpair = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM,
@@ -485,9 +485,9 @@ class Sac_a_push {
         unset($this->socks[$id]);
     }
 
-    function pgflush_try_add($enc, &$new_socket, $tout, $header_out, $content)
+    function pendpage_try_addflush($enc, &$new_socket, $tout, $header_out, $content)
     {
-        $pgflush = new PageFlush($new_socket, $enc, $this->curtime, $tout, $header_out, $content);
+        $pgflush = PendingPage::pendingpage_flushing($new_socket, $enc, $this->curtime, $tout, $header_out, $content);
 
         if ($pgflush->try_flush($this->curtime) == FALSE) {
             // Add $pgflush to the pgflush array
@@ -497,7 +497,7 @@ class Sac_a_push {
 
     function pgflush_add($pgflush)
     {
-        array_push($this->pages_flush, $pgflush);
+        array_push($this->pending_pages, $pgflush);
     }
 
     function garbage_manager($force)
@@ -539,7 +539,7 @@ class Sac_a_push {
         
         while ($this->main_loop) {
             $this->curtime = time();
-            printf("IN LOOP: Current opened: %d  pages_flush: %d - ", count($this->socks), count($this->pages_flush));
+            printf("IN LOOP: Current opened: %d  pending_pages: %d - ", count($this->socks), count($this->pending_pages));
             
             /* Prepare the read array */
             /* // when we manage it ... */
@@ -684,9 +684,10 @@ class Sac_a_push {
             $this->garbage_manager(FALSE);
 
             /* manage unfinished pages */
-            foreach ($this->pages_flush as $k => $pgflush) {
+            foreach ($this->pending_pages as $k => $pgflush) {
+                // TODO: try_flush if exists in the class
                 if ($pgflush->try_flush($this->curtime) == TRUE) {
-                    unset($this->pages_flush[$k]);
+                    unset($this->pending_pages[$k]);
                 }
             }
             
index 354637a..fdd578f 100644 (file)
@@ -1207,7 +1207,7 @@ class Bin5 {
             $content = ob_get_contents();
             ob_end_clean();
         
-            $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+            $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
             return TRUE;
         
         break;
@@ -1227,7 +1227,7 @@ class Bin5 {
             else {
                 $content = "Bin5 Load data error";
             }
-            $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+            $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
             return TRUE;
             
             break;
@@ -1240,7 +1240,7 @@ class Bin5 {
                     || (($user = $bri->get_user($cookie['sess'], $idx)) == FALSE)) {
 
                     $content = Bin5_user::stream_fini($transp_type, $s_a_p->rndstr, TRUE);
-                    $s_a_p->pgflush_try_add($enc, $new_socket, 20, $header_out, $content);
+                    $s_a_p->pendpage_try_addflush($enc, $new_socket, 20, $header_out, $content);
 
                     return TRUE;
                     break;
index e9382dd..3de49ef 100644 (file)
@@ -26,14 +26,48 @@ $DOCUMENT_ROOT="";
 $HTTP_HOST="dodo.birds.lan";
 define('USOCK_PATH', "/tmp/brisk.sock");
 
-class PageFlush {
+define('PENDINGPAGE_WAITDATA', 0);
+define('PENDINGPAGE_FLUSHING', 1);
+
+class PendingPage {
 
   var $socket; // socket handler of page stream
+  var $status; // status can be 0: waiting for data, 1: flush phase
+
   var $kalive; // if no message are sent after RD_KEEPALIVE_TOUT secs we send a keepalive from server
   var $msg;    // place where store failed fwrite data
   var $msg_sz; // size of content
 
-  function PageFlush($socket, $enc, $curtime, $kalive, $header_out, $body)
+  
+
+  function PendingPage($socket)
+  {
+      $this->socket = $socket;
+  }
+
+  static function pendingpage_waiting($socket, $method, $header, $get, $post, $cookie, $path, $addr)
+  {
+      $thiz = new PendingPage($socket);
+
+      // TODO
+  }
+
+  function try_wait($curtime)
+  {
+      // if completed return TRUE to allow data to be processed, 
+      // if timeout or max content dimension is exceeded move to flushing
+  }
+
+  static function pendingpage_flushing($socket, $enc, $curtime, $kalive, $header_out, $body)
+  {
+      $thiz = new PendingPage($socket);
+
+      $thiz->to_flushing($enc, $curtime, $kalive, $header_out, $body);
+
+      return ($thiz);
+  }
+
+  function to_flushing($enc, $curtime, $kalive, $header_out, $body)
   {
       printf("TRY FLUSH CREATE\n");
       $body_out = ZLibStream::compress($enc, $body);
@@ -43,7 +77,7 @@ class PageFlush {
       $hea = headers_render($header_out, $body_out_sz);
       $hea_sz = mb_strlen($hea, "ASCII");
 
-      $this->socket = $socket;
+      $this->status = PENDINGPAGE_FLUSHING;
       $this->kalive = $curtime + $kalive;
       $this->msg    = $hea.$body_out;
       $this->msg_sz = $hea_sz + $body_out_sz;
@@ -52,6 +86,9 @@ class PageFlush {
   /* return TRUE if is removable from it's list */
   function try_flush($curtime)
   {
+      if ($this->status != PENDINGPAGE_FLUSHING)
+          return (FALSE);
+
       printf("TRY FLUSH IN\n");
       if ($this->kalive < $curtime) {
           printf("TRY FLUSH CLOSE 1\n");
@@ -61,7 +98,7 @@ class PageFlush {
 
       $wret = @fwrite($this->socket, $this->msg);
       if ($wret == FALSE && $wret !== FALSE) {
-          printf("TRY FLUSH PageFlush::try_flush: wret 0 but not FALSE\n");
+          printf("TRY FLUSH PendingPage::try_flush: wret 0 but not FALSE\n");
       }
       if ($wret == $this->msg_sz) {
           printf("TRY FLUSH CLOSE 2\n");