X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fsac-a-push.phh;h=c9220a1f13ff9f5cb47594e6bf6dbef8fdbee542;hb=7bb29caf1761665d81089090d1df1153b5d2bab9;hp=3c66c126f52a29e0c7f27bbb087dbf4bcbb4df21;hpb=65c6a676cf9a655d33fa48441b1c7390492163fa;p=brisk.git diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index 3c66c12..c9220a1 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -24,6 +24,7 @@ */ define('SITE_PREFIX', '/brisk/'); +define('SITE_PREFIX_LEN', 7); function spu_process_info($stream_info, $method, &$header, &$get, &$post, &$cookie) { @@ -104,9 +105,13 @@ function gpcs_var($name, $get, $post, $cookie) function headers_render($header, $len) { - $s = ""; - $s .= "HTTP/1.1 200 OK\r\n"; + if (isset($header['Location'])) { + return sprintf("HTTP/1.1 302 OK\r\nLocation: %s\r\n\r\n", $header['Location']); + } + else { + $s .= "HTTP/1.1 200 OK\r\n"; + } if (!isset($header['Date'])) $s .= sprintf("Date: %s\r\n", date(DATE_RFC822)); if (!isset($header['Connection'])) @@ -173,7 +178,7 @@ class Sac_a_push { var $debug; var $blocking_mode; - var $room; + var $app; var $bin5; var $curtime; @@ -187,11 +192,11 @@ class Sac_a_push { // Sac_a_push::create("/tmp/brisk.sock", 0, 0 - static function create(&$room, $sockname, $debug, $blocking_mode) + static function create(&$app, $sockname, $debug, $blocking_mode) { $thiz = new Sac_a_push(); - $thiz->room = $room; + $thiz->app = $app; $thiz->file_socket = $sockname; $thiz->unix_socket = "unix://$sockname"; $thiz->debug = $debug; @@ -283,7 +288,7 @@ class Sac_a_push { } $write = NULL; $except = NULL; - $num_changed_sockets = stream_select($read, $write, $except, 0, 250000); + $num_changed_sockets = stream_select($read, $write, $except, 5, 0); if ($num_changed_sockets == 0) { printf(" no data in 5 secs "); @@ -326,7 +331,16 @@ class Sac_a_push { $addr = stream_socket_get_name($new_socket, TRUE); $header_out = array(); - $this->room->request_mgr($this, $header_out, $new_socket, $path, $addr, $get, $post, $cookie); + $subs = SITE_PREFIX."briskin5/"; + $subs_l = strlen($subs); + $rret = FALSE; + if (!strncmp($path, SITE_PREFIX, SITE_PREFIX_LEN)) { + $rret = $this->app->request_mgr($this, $header_out, $new_socket, substr($path, SITE_PREFIX_LEN), $addr, $get, $post, $cookie); + } + if ($rret == FALSE) { + // FIXME: manage 404 !!! + printf("TODO: fix unknown page\n"); + } printf("number of sockets after %d\n", count($this->socks)); } else { @@ -336,7 +350,6 @@ class Sac_a_push { else { if (($buf = fread($sock, 512)) === FALSE) { printf("error read\n"); - exit(123); } else if (strlen($buf) === 0) { if ($sock === $this->list) { @@ -361,7 +374,7 @@ class Sac_a_push { } } else { - if ($debug > 1) { + if ($this->debug > 1) { print_r($read); } if ($sock === $this->list) { @@ -380,6 +393,9 @@ class Sac_a_push { } + $this->app->garbage_manager(FALSE); + + /* manage unfinished pages */ foreach ($this->pages_flush as $k => $pgflush) { if ($pgflush->try_flush($this->curtime) == TRUE) { @@ -387,17 +403,32 @@ class Sac_a_push { } } + /* + $response: raw stream data not sent + $content: html consistent data (