use $GLOBALS instead of assuming vars declared outside of a function will be global. allows it to work inside a create_function() eval
git-svn-id: file:///home/svn/framework3/trunk@9597 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
099b90b0d6
commit
c9c3e806a5
|
@ -1,23 +1,23 @@
|
||||||
#<?php
|
#<?php
|
||||||
|
|
||||||
# global list of channels
|
# global list of channels
|
||||||
if (!isset($channels)) {
|
if (!isset($GLOBALS['channels'])) {
|
||||||
$channels = array();
|
$GLOBALS['channels'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
# global resource map. This is how we know whether to use socket or stream
|
# global resource map. This is how we know whether to use socket or stream
|
||||||
# functions on a channel.
|
# functions on a channel.
|
||||||
if (!isset($resource_type_map)) {
|
if (!isset($GLOBALS['resource_type_map'])) {
|
||||||
$resource_type_map = array();
|
$GLOBALS['resource_type_map'] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
# global list of resources we need to watch in the main select loop
|
# global list of resources we need to watch in the main select loop
|
||||||
#if (!isset($readers)) {
|
if (!isset($GLOBALS['readers'])) {
|
||||||
$readers = array();
|
$GLOBALS['readers'] = array();
|
||||||
#}
|
}
|
||||||
|
|
||||||
function my_print($str) {
|
function my_print($str) {
|
||||||
error_log($str);
|
#error_log($str);
|
||||||
#print($str ."\n");
|
#print($str ."\n");
|
||||||
#flush();
|
#flush();
|
||||||
}
|
}
|
||||||
|
@ -731,8 +731,8 @@ function select(&$r, &$w, &$e, $tv_sec=0, $tv_usec=0) {
|
||||||
if ($r) {
|
if ($r) {
|
||||||
foreach ($r as $resource) {
|
foreach ($r as $resource) {
|
||||||
switch (get_rtype($resource)) {
|
switch (get_rtype($resource)) {
|
||||||
case 'socket': array_push($sockets_r, $resource); break;
|
case 'socket': $sockets_r[] = $resource; break;
|
||||||
case 'stream': array_push($streams_r, $resource); break;
|
case 'stream': $streams_r[] = $resource; break;
|
||||||
default: my_print("Unknown resource type"); break;
|
default: my_print("Unknown resource type"); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -740,8 +740,8 @@ function select(&$r, &$w, &$e, $tv_sec=0, $tv_usec=0) {
|
||||||
if ($w) {
|
if ($w) {
|
||||||
foreach ($w as $resource) {
|
foreach ($w as $resource) {
|
||||||
switch (get_rtype($resource)) {
|
switch (get_rtype($resource)) {
|
||||||
case 'socket': array_push($sockets_w, $resource); break;
|
case 'socket': $sockets_w[] = $resource; break;
|
||||||
case 'stream': array_push($streams_w, $resource); break;
|
case 'stream': $streams_w[] = $resource; break;
|
||||||
default: my_print("Unknown resource type"); break;
|
default: my_print("Unknown resource type"); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,8 +749,8 @@ function select(&$r, &$w, &$e, $tv_sec=0, $tv_usec=0) {
|
||||||
if ($e) {
|
if ($e) {
|
||||||
foreach ($e as $resource) {
|
foreach ($e as $resource) {
|
||||||
switch (get_rtype($resource)) {
|
switch (get_rtype($resource)) {
|
||||||
case 'socket': array_push($sockets_e, $resource); break;
|
case 'socket': $sockets_e[] = $resource; break;
|
||||||
case 'stream': array_push($streams_e, $resource); break;
|
case 'stream': $streams_e[] = $resource; break;
|
||||||
default: my_print("Unknown resource type"); break;
|
default: my_print("Unknown resource type"); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -758,7 +758,7 @@ function select(&$r, &$w, &$e, $tv_sec=0, $tv_usec=0) {
|
||||||
|
|
||||||
$n_sockets = count($sockets_r) + count($sockets_w) + count($sockets_e);
|
$n_sockets = count($sockets_r) + count($sockets_w) + count($sockets_e);
|
||||||
$n_streams = count($streams_r) + count($streams_w) + count($streams_e);
|
$n_streams = count($streams_r) + count($streams_w) + count($streams_e);
|
||||||
my_print("Selecting $n_sockets sockets and $n_streams streams");
|
my_print("Selecting $n_sockets sockets and $n_streams streams with timeout $tv_sec.$tv_usec");
|
||||||
$r = array();
|
$r = array();
|
||||||
$w = array();
|
$w = array();
|
||||||
$e = array();
|
$e = array();
|
||||||
|
@ -802,7 +802,6 @@ function add_reader($resource) {
|
||||||
|
|
||||||
function remove_reader($resource) {
|
function remove_reader($resource) {
|
||||||
global $readers;
|
global $readers;
|
||||||
my_print("Readers $readers");
|
|
||||||
if (in_array($resource, $readers)) {
|
if (in_array($resource, $readers)) {
|
||||||
foreach ($readers as $key => $r) {
|
foreach ($readers as $key => $r) {
|
||||||
if ($r == $resource) {
|
if ($r == $resource) {
|
||||||
|
@ -859,11 +858,14 @@ if (!isset($msgsock)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($msgsock_type) {
|
switch ($msgsock_type) {
|
||||||
case 'socket': register_socket($msgsock); break;
|
case 'socket':
|
||||||
|
register_socket($msgsock);
|
||||||
|
break;
|
||||||
case 'stream':
|
case 'stream':
|
||||||
# fall through
|
# fall through
|
||||||
default:
|
default:
|
||||||
register_stream($msgsock); break;
|
register_stream($msgsock);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
add_reader($msgsock);
|
add_reader($msgsock);
|
||||||
|
@ -871,9 +873,8 @@ add_reader($msgsock);
|
||||||
#
|
#
|
||||||
# Main dispatch loop
|
# Main dispatch loop
|
||||||
#
|
#
|
||||||
$r=$readers;
|
$r=$GLOBALS['readers'];
|
||||||
while (false !== ($cnt = select($r, $w=null, $e=null, 1))) {
|
while (false !== ($cnt = select($r, $w=null, $e=null, 1))) {
|
||||||
dump_array($r);
|
|
||||||
my_print(sprintf("Returned from select with %s readers", count($r)));
|
my_print(sprintf("Returned from select with %s readers", count($r)));
|
||||||
$read_failed = false;
|
$read_failed = false;
|
||||||
for ($i = 0; $i < $cnt; $i++) {
|
for ($i = 0; $i < $cnt; $i++) {
|
||||||
|
@ -914,9 +915,7 @@ while (false !== ($cnt = select($r, $w=null, $e=null, 1))) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dump_readers();
|
$r = $GLOBALS['readers'];
|
||||||
dump_resource_map();
|
|
||||||
$r=$readers;
|
|
||||||
} # end main loop
|
} # end main loop
|
||||||
my_print("Finished");
|
my_print("Finished");
|
||||||
close($msgsock);
|
close($msgsock);
|
||||||
|
|
Loading…
Reference in New Issue