moved chunked_content into user class and set chunked as optional
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 16 Aug 2013 08:50:24 +0000 (10:50 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Fri, 16 Aug 2013 08:50:24 +0000 (10:50 +0200)
web/Obj/brisk.phh
web/Obj/sac-a-push.phh
web/Obj/transports.phh
web/Obj/user.phh
web/briskin5/Obj/briskin5.phh

index d90c2ea..593b6e2 100644 (file)
@@ -2368,7 +2368,7 @@ class Room
               $content = "";
               $user->stream_init($s_a_p->rndstr, $enc, $header_out, $content, $get, $post, $cookie);
               
-              $response = headers_render($header_out, -1).chunked_content($user->rd_zls_get(), $content);
+              $response = headers_render($header_out, -1).$user->chunked_content($content);
               $response_l = mb_strlen($response, "ASCII");
               
               $wret = @fwrite($new_socket, $response, $response_l);
index c0e2db1..502670d 100644 (file)
@@ -268,25 +268,6 @@ register_shutdown_function('shutta');
  *  MAIN
  */
 
-function chunked_content($zls, $content)
-{
-    if ($zls) {
-        $cont_comp = $zls->compress_chunk($content);
-    }
-    else {
-        $cont_comp = $content;
-    }
-    $cont_comp_l = mb_strlen($cont_comp, "ASCII");
-    // printf("CHUNK: [%s]\n", $content);
-
-    return (sprintf("%X\r\n", $cont_comp_l).$cont_comp."\r\n");
-}
-
-function chunked_fini()
-{
-    return sprintf("0\r\n");
-}
-
 function get_encoding($header)
 {
     $enc = "plain";
@@ -860,7 +841,7 @@ class Sac_a_push {
                             $content = $user->stream_keepalive(FALSE);
                         }
                         if ($content != "") {
-                            $response = chunked_content($user->rd_zls_get(), $content);
+                            $response = $user->chunked_content($content);
                         }
                     }
                     
index 2d9714e..a77fad7 100644 (file)
@@ -69,6 +69,10 @@ class Transport_template {
     function chunk($step, $cont)
     {
     }
+
+    function is_chunked()
+    {
+    }
 }
 
 class Transport_xhr {
@@ -98,6 +102,11 @@ class Transport_xhr {
     {
         return ("@BEGIN@".$cont."@END@");
     }
+
+    function is_chunked()
+    {
+        return TRUE;
+    }
 }
 
 class Transport_iframe {
@@ -166,6 +175,11 @@ push(null);\n// -->\n</script>", $step);
 push(\"%s\");\n// -->\n</script>", $step, escpush($cont) );
         }
     }
+
+    function is_chunked()
+    {
+        return TRUE;
+    }
 }
 
 class Transport_htmlfile extends Transport_iframe {
index 11b808f..f52bc3e 100644 (file)
@@ -108,6 +108,7 @@ class User {
   var $rd_cache;   // place where store failed fwrite data
   var $rd_zls;     // zlibstream object handle if compressed stream, else FALSE
   var $rd_transp;  // class that define stream encapsulation type (iframe, xhr, ...)
+  var $rd_is_chunked; // is the transport chunked or not ?
 
   var $comm;       // commands array
   // var $asta_card;  // 
@@ -168,6 +169,7 @@ class User {
     $thiz->rd_cache   = "";
     $thiz->rd_zls     = FALSE;
     $thiz->rd_transp  = NULL;
+    $thiz->rd_is_chunked = FALSE;
 
     $thiz->asta_card  = -2;
     $thiz->asta_pnt   = -1;
@@ -330,6 +332,7 @@ class User {
       $this->rd_kalive  = $curtime + RD_KEEPALIVE_TOUT;
       $this->rd_zls     = ZLibStream::create($enc);
       $this->rd_transp  = Transport::create($transp);
+      $this->rd_is_chunked = $this->rd_transp->is_chunked();
   }
 
   function rd_socket_get() {
@@ -779,6 +782,37 @@ function is_supp_custom()
     return (FALSE);
 }
 
+function is_chunked()
+{
+    return $this->rd_is_chunked;
+}
+
+
+function chunked_content($content)
+{
+    if ($this->rd_zls) {
+        $cont_comp = $this->rd_zls->compress_chunk($content);
+    }
+    else {
+        $cont_comp = $content;
+    }
+    $cont_comp_l = mb_strlen($cont_comp, "ASCII");
+    // printf("CHUNK: [%s]\n", $content);
+
+    if ($this->is_chunked()) {
+        return (sprintf("%X\r\n", $cont_comp_l).$cont_comp."\r\n");
+    }
+    else {
+        return $content;
+    }
+}
+
+function chunked_fini()
+{
+    return sprintf("0\r\n");
+}
+
+
 } // end class User
 
 
index 10edf1b..6e3a52f 100644 (file)
@@ -1234,7 +1234,7 @@ class Bin5 {
                 
                 $content = "";
                 $user->stream_init($s_a_p->rndstr, $enc, $header_out, $content, $get, $post, $cookie);
-                $response = headers_render($header_out, -1).chunked_content($user->rd_zls_get(), $content);
+                $response = headers_render($header_out, -1).$user->chunked_content($content);
                 $response_l = mb_strlen($response, "ASCII");
                 
                 $wret = @fwrite($new_socket, $response, $response_l);