X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fsac-a-push.phh;h=04f7c5baa34caed3fb6c9119578014d34ce3f5ac;hb=43cab39ea58529cd2442c28f4157bb7efc97856f;hp=bc0ea8723922f408766710593460d4f2f9e5a557;hpb=64168bc6e7d5cfe46ac0120bb7b449b5d5f37c1b;p=brisk.git diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index bc0ea87..04f7c5b 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -105,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'])) @@ -258,6 +262,23 @@ class Sac_a_push { array_push($this->pages_flush, $pgflush); } + function garbage_manager($force) + { + $this->app->garbage_manager($force); + + foreach ($this->socks as $k => $sock) { + if ($this->s2u[intval($sock)]->sess == '') { + if ($this->s2u[intval($sock)]->rd_socket_get() != NULL) { + $this->s2u[intval($sock)]->rd_socket_set(NULL); + } + unset($this->socks[intval($sock)]); + unset($this->s2u[intval($sock)]); + fclose($sock); + printf("CLOSE ON GARBAGE MANAGER\n"); + } + } + } + function run() { if ($this->main_loop) { @@ -284,7 +305,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, 0, 500000); if ($num_changed_sockets == 0) { printf(" no data in 5 secs "); @@ -303,7 +324,10 @@ class Sac_a_push { } if ($sock === $this->list) { printf("NUOVA CONNEX\n"); - $new_unix = stream_socket_accept($this->list); + if (($new_unix = stream_socket_accept($this->list)) == FALSE) { + printf("SOCKET_ACCEPT FAILED\n"); + continue; + } $stream_info = ""; $method = ""; $get = array(); @@ -344,15 +368,18 @@ class Sac_a_push { } } else { - if (($buf = fread($sock, 512)) === FALSE) { - printf("error read\n"); - } - else if (strlen($buf) === 0) { + $buf = fread($sock, 512); + if ($buf == FALSE || strlen($buf) == 0) { + if ($buf == FALSE) { + printf("ERROR READING\n"); + } if ($sock === $this->list) { printf("Arrivati %d bytes da list\n", strlen($buf)); + exit(21); } else if ($sock === $this->in) { printf("Arrivati %d bytes da stdin\n", strlen($buf)); + exit(22); } else { // $user_a[$s2u[intval($sock)]]->disable(); @@ -361,9 +388,10 @@ class Sac_a_push { } unset($this->socks[intval($sock)]); unset($this->s2u[intval($sock)]); - fclose($sock); - printf("CLOSE ON READ\n"); } + fclose($sock); + printf("CLOSE ON READ\n"); + if ($this->debug > 1) { printf("post unset\n"); print_r($this->socks); @@ -387,10 +415,8 @@ class Sac_a_push { } } } - - - $this->app->garbage_manager(FALSE); + $this->garbage_manager(FALSE); /* manage unfinished pages */ foreach ($this->pages_flush as $k => $pgflush) { @@ -399,17 +425,35 @@ class Sac_a_push { } } + /* + $response: raw stream data not sent + $content: html consistent data (