methods and logic to manage static Brisk attrib sess_cur added
[brisk.git] / web / Obj / sac-a-push.phh
index 08ced76..27ed4c4 100644 (file)
@@ -404,6 +404,7 @@ class Sac_a_push {
     var $s2u;             // user associated with input socket
     var $s2p;             // pending page associated with input socket
     var $pending_pages;
+    var $is_daemon;
 
     var $list;
     var $in;
@@ -446,7 +447,7 @@ class Sac_a_push {
         }
     }
 
-    static function create(&$app, $sockname, $debug, $blocking_mode)
+    static function create(&$app, $sockname, $debug, $blocking_mode, $argv)
     {        
         $thiz = new Sac_a_push();
         
@@ -458,6 +459,11 @@ class Sac_a_push {
         $thiz->s2u  = array();
         $thiz->s2p  = array();
         $thiz->pending_pages = array();
+        $thiz->is_daemon = FALSE;
+
+        if (array_search("-d", $argv) !== FALSE || array_search("--daemon", $argv) !== FALSE) {
+            $thiz->is_daemon = TRUE;
+        }
 
         // create a couple of sockets for control management
         if (($sockpair = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM,
@@ -611,7 +617,7 @@ class Sac_a_push {
         GLOBAL $G_splash_w, $G_topbanner, $G_with_donors, $G_with_poll;
         GLOBAL $G_with_sidebanner, $G_with_sidebanner2, $G_with_splash;
         GLOBAL $G_with_topbanner;
-        GLOBAL $G_tos_vers, $G_tos_fname, $G_tos_dtsoft, $G_tos_dthard, $G_tos_idx;
+        GLOBAL $G_tos_vers, $G_tos_fname, $G_tos_dtsoft, $G_tos_dthard, $G_tos_idx, $G_doc_path;
 
         if ($this->main_loop) {
             return (FALSE);
@@ -620,6 +626,7 @@ class Sac_a_push {
         $this->main_loop = TRUE;
         
         while ($this->main_loop) {
+            $this->app->sess_cur_set(FALSE);
             $this->curtime = time();
             fprintf(STDERR, "IN LOOP: Current opened: %d  pending_pages: %d\n", count($this->socks), count($this->pending_pages));
             
@@ -628,9 +635,15 @@ class Sac_a_push {
             /* if ($shutdown)  */
             /*     $read   = array_merge(array("$in" => $in), $socks); */
             /* else */
-            $read   = array_merge(array(intval($this->list) => $this->list, intval($this->in) => $this->in,
-                                        intval(static::$cnt_slave) => static::$cnt_slave),
-                                  $this->socks);
+            $pre_read = array_merge(array(intval($this->list) => $this->list,
+                                          intval(static::$cnt_slave) => static::$cnt_slave),
+                                    $this->socks);
+            if ($this->is_daemon == FALSE) {
+                $read = array_merge($pre_read, array(intval($this->in) => $this->in));
+            }
+            else {
+                $read = $pre_read;
+            }
             
             if ($this->debug > 1) {
                 printf("PRE_SELECT\n");
@@ -803,7 +816,6 @@ class Sac_a_push {
                         if (!strncmp($path, SITE_PREFIX, SITE_PREFIX_LEN)) {
                             $rret = $this->app->request_mgr($this, $header, $header_out, $new_socket, substr($path, SITE_PREFIX_LEN), $addr, $get, $post, $cookie);
                         }
-                        fprintf(STDERR, "\n\n DI QUI PASSA [%s]\n\n", $rret);
                         if ($rret == FALSE) {
                             // FIXME: manage 404 !!!
                             printf("TODO: fix unknown page\n");