consolidate debugging functions in the file

git-svn-id: file:///home/svn/framework3/trunk@9517 4d416f70-5f16-0410-b530-b9f4589650da
unstable
James Lee 2010-06-15 00:33:24 +00:00
parent 7498c30b30
commit dacd38c49c
1 changed files with 26 additions and 20 deletions

View File

@ -3,12 +3,34 @@
# a // for the comment instead of # so that the comment remover doesn't blow it # a // for the comment instead of # so that the comment remover doesn't blow it
# away. # away.
function my_print($str) { function my_print($str) {
#error_log($str); #error_log($str);
#print($str ."\n"); #print($str ."\n");
#flush(); #flush();
} }
function dump_array($arr, $name=null) {
if (is_null($name)) {
my_print(sprintf("Array (%s)", count($arr)));
} else {
my_print(sprintf("$name (%s)", count($arr)));
}
foreach ($arr as $key => $val) {
$foo = sprintf(" $key ($val)");
my_print($foo);
}
}
function dump_readers() {
global $readers;
dump_array($readers, 'Readers');
}
function dump_resource_map() {
global $resource_type_map;
dump_array($resource_type_map, 'Resource map');
}
# Doesn't exist before php 4.3 # Doesn't exist before php 4.3
if (!function_exists("file_get_contents")) { if (!function_exists("file_get_contents")) {
function file_get_contents($file) { function file_get_contents($file) {
@ -665,6 +687,9 @@ function core_channel_open($req, &$pkt) {
$type_tlv = packet_get_tlv($req, TLV_TYPE_CHANNEL_TYPE); $type_tlv = packet_get_tlv($req, TLV_TYPE_CHANNEL_TYPE);
my_print("Client wants a ". $type_tlv['value'] ." channel, i'll see what i can do"); my_print("Client wants a ". $type_tlv['value'] ." channel, i'll see what i can do");
# Doing it this way allows extensions to create new channel types without
# needing to modify the core code.
$handler = "channel_create_". $type_tlv['value']; $handler = "channel_create_". $type_tlv['value'];
if ($type_tlv['value'] && is_callable($handler)) { if ($type_tlv['value'] && is_callable($handler)) {
$ret = $handler($req, $pkt); $ret = $handler($req, $pkt);
@ -682,6 +707,7 @@ function core_channel_eof($req, &$pkt) {
$c = get_channel_by_id($chan_tlv['value']); $c = get_channel_by_id($chan_tlv['value']);
if ($c) { if ($c) {
# XXX Doesn't work with sockets.
if (@feof($c[1])) { if (@feof($c[1])) {
packet_add_tlv($pkt, create_tlv(TLV_TYPE_BOOL, 1)); packet_add_tlv($pkt, create_tlv(TLV_TYPE_BOOL, 1));
} else { } else {
@ -1037,26 +1063,6 @@ function register_stream($stream) {
$resource_type_map[(int)$stream] = 'stream'; $resource_type_map[(int)$stream] = 'stream';
} }
function dump_array($arr, $name=null) {
if (is_null($name)) {
my_print(sprintf("Array (%s)", count($arr)));
} else {
my_print(sprintf("$name (%s)", count($arr)));
}
foreach ($arr as $key => $val) {
$foo = sprintf(" $key ($val)");
my_print($foo);
}
}
function dump_readers() {
global $readers;
dump_array($readers, 'Readers');
}
function dump_resource_map() {
global $resource_type_map;
dump_array($resource_type_map, 'Resource map');
}
function close($resource) { function close($resource) {
my_print("Closing resource $resource"); my_print("Closing resource $resource");
global $readers, $resource_type_map; global $readers, $resource_type_map;