* Suite 330, Boston, MA 02111-1307, USA.
*
* TODO
+ * problema con getpeer (HOSTADDR)
* setcookie (for tables only)
* keepalive
* chunked
}
$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");
$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);
-
-
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);
+ }
}
}
}