X-Git-Url: http://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fspush%2Fbrisk-spush.php;h=1f3d7e4bc0053862d9d033d60190186afdc2e66c;hb=525cfe7d868bfaefdde9f769f52a50bcb6f1e9e9;hp=f5c944e819ad4cf470cb8a63146969f6e277270c;hpb=c3ccbbd5bc7c8534127fa10b4f88b81cffc6029a;p=brisk.git diff --git a/web/spush/brisk-spush.php b/web/spush/brisk-spush.php index f5c944e..1f3d7e4 100755 --- a/web/spush/brisk-spush.php +++ b/web/spush/brisk-spush.php @@ -22,6 +22,7 @@ * Suite 330, Boston, MA 02111-1307, USA. * * TODO + * problema con getpeer (HOSTADDR) * setcookie (for tables only) * keepalive * chunked @@ -228,7 +229,7 @@ function main() } $write = NULL; $except = NULL; - $num_changed_sockets = stream_select($read, $write, $except, 5); + $num_changed_sockets = stream_select($read, $write, $except, 1); // 0, 250000); if ($num_changed_sockets === FALSE) { printf("No data in 5 secs"); @@ -267,17 +268,22 @@ function main() $header_out = array(); ob_start(); index_main($room, $header_out, $get, $post, $cookie); - $content = ob_get_flush(); - + $content = ob_get_contents(); + ob_end_clean(); // printf("OUT: [%s]\n", $G_content); fwrite($new_socket, headers_render($header_out).$content); fclose($new_socket); break; case SITE_PREFIX."index_wr.php": $G_headers = ""; + $addr = ""; + $ret = socket_getpeername($new_socket, $addr); + // printf("RET: %d\n", $ret); + // exit(123); ob_start(); - index_wr_main($room, socket_getpeername($$new_socket), $get, $post, $cookie); - $content = ob_get_flush(); + index_wr_main($room, $addr, $get, $post, $cookie); + $content = ob_get_contents(); + ob_end_clean(); // printf("OUT: [%s]\n", $G_content); fwrite($new_socket, headers_render($header_out).$content); @@ -403,19 +409,35 @@ function main() - - foreach ($socks as $k => $sock) { if (isset($s2u[intval($sock)])) { $body = ""; - $header_out = array(); $body = ""; - index_rd_ifra_main($room, $room->user[$s2u[intval($sock)]], $body); - echo "SPIA: [$body]\n"; - fwrite($sock, headers_render($header_out).$body); - fflush($sock); + $user = $room->user[$s2u[intval($sock)]]; + index_rd_ifra_main($room, $user, $body); + if ($body == "" && $user->rd_tout_is_expired($curtime)) { + $body = index_rd_ifra_keepalive($user); + } + + if ($body != "") { + echo "SPIA: [".substr($body, 0, 60)."...]\n"; + fwrite($sock, $body); + fflush($sock); + $user->rd_tout_reset($curtime); + } + + // close socket after a while to prevent client memory consumption + if ($user->rd_endtime_is_expired($curtime)) { + // $user_a[$s2u[intval($sock)]]->disable(); + if ($room->user[$s2u[intval($sock)]]->rd_socket_get() != NULL) { + $room->user[$s2u[intval($sock)]]->rd_socket_set(NULL); + } + unset($socks[intval($sock)]); + unset($s2u[intval($sock)]); + fclose($sock); + } } } }