File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,25 @@ sysinfo {
47
47
$c -> ledge_get(' sysinfo' ) || [];
48
48
};
49
49
50
+ sub read_result {
51
+ my $client = shift ;
52
+ my $prefix = $client -> read (1);
53
+ while ($prefix !~ / \r\n / ) {
54
+ my $tmp = $client -> read (1);
55
+ die " could not retrieve whole string" if $tmp == ' ' ;
56
+ $prefix = $prefix . $tmp ;
57
+ }
58
+ my ($length , $buffer ) = ( split /\r\n/, $prefix , 2 );
59
+ $length =~ s /\$ // g ;
60
+ while (length ($buffer ) != $length + 2) { # prefixed length terminated by CRLF
61
+ my $tmp = $client -> read (1);
62
+ die " could not retrieve whole string" if $tmp == ' ' ;
63
+ $buffer = $buffer . $tmp ;
64
+ }
65
+ die " string is not finished CRLF" if $buffer !~ / \r\n\z / ;
66
+ $buffer =~ s /\r\n\z // g ;
67
+ return length ($buffer ) == $length ? $buffer : undef ;
68
+ }
50
69
51
70
fetcher {
52
71
my $c = shift ;
@@ -56,7 +75,7 @@ fetcher {
56
75
57
76
my $client = CloudForecast::TinyClient-> new($host ,$port ,3.5);
58
77
$client -> write (" info\r\n " ,1);
59
- my $raw_stats = $client -> read (1 );
78
+ my $raw_stats = read_result( $client );
60
79
die " could not retrieve status from $host :$port " unless $raw_stats ;
61
80
62
81
my %stats ;
You can’t perform that action at this time.
0 commit comments