X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fsac-a-push.phh;h=27ed4c4f5f70fa9c35378aa72d9f384c0aa4cc7f;hb=059f6fcca909267802697e22ac7c8b701b9ed14e;hp=c0e2db1644e992201e218a4eedc7433b0c892745;hpb=473544e3d3756da00d1c3e6b7995394cb3931cc1;p=brisk.git diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index c0e2db1..27ed4c4 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -221,6 +221,14 @@ function headers_render($header, $len) } else if (isset($header['HTTP-Response'])) { $s = sprintf("HTTP/1.1 %s\r\n", $header['HTTP-Response']); + foreach($header as $key => $value) { + if (strtolower($key) == "http-response") + continue; + $s .= sprintf("%s: %s\r\n", $key, $value); + } + if ($len >= 0) { + $s .= sprintf("Content-Length: %ld\r\n", $len); + } } else { $s = "HTTP/1.1 200 OK\r\n"; @@ -268,25 +276,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"; @@ -415,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; @@ -457,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(); @@ -469,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, @@ -622,6 +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, $G_doc_path; if ($this->main_loop) { return (FALSE); @@ -630,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)); @@ -638,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"); @@ -720,7 +723,7 @@ class Sac_a_push { if ($buf == FALSE || mb_strlen($buf, "ASCII") == 0) { // close socket case if ($buf == FALSE) { - printf("ERROR READING\n"); + printf("INFO: read return false\n"); } if ($sock === $this->list) { printf("Arrivati %d bytes da list\n", mb_strlen($buf, "ASCII")); @@ -735,6 +738,10 @@ class Sac_a_push { if (isset($this->s2u[$id])) { // $user_a[$s2u[$id]]->disable(); if ($this->s2u[$id]->rd_socket_get() != NULL) { + // try to send close frame (for websocket) + $clo = $this->s2u[$id]->stream_close(); + $clo_l = mb_strlen($clo, "ASCII"); + @fwrite($sock, $clo, $clo_l); $this->s2u[$id]->rd_socket_set(NULL); } unset($this->s2u[$id]); @@ -763,7 +770,7 @@ class Sac_a_push { global_dump(); } - else if ($line == "shutdown") { + else if ($line == "shutdown" || $line == "sd") { if ($this->app->dump_data()) { return(0); } @@ -809,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"); @@ -860,7 +866,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); } } @@ -868,7 +874,7 @@ class Sac_a_push { // echo "SPIA: [".substr($response, 0, 60)."...]\n"; // echo "SPIA: [".$response."]\n"; $response_l = mb_strlen($response, "ASCII"); - $wret = @fwrite($sock, $response); + $wret = @fwrite($sock, $response, $response_l); if ($wret < $response_l) { printf("TROUBLE WITH FWRITE: %d\n", $wret); $user->rd_cache_set(mb_substr($response, $wret, $response_l - $wret, "ASCII")); @@ -887,6 +893,9 @@ class Sac_a_push { } unset($this->socks[$id]); unset($this->s2u[$id]); + $clo = $user->stream_close(); + $clo_l = mb_strlen($clo, "ASCII"); + @fwrite($sock, $clo, $clo_l); fclose($sock); printf("CLOSE ON LOOP\n"); }