[TS-3254] : patch from James to fix perl get_stats API
Conflicts:
CHANGES
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/d260d201
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/d260d201
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/d260d201
Branch: refs/heads/5.2.x
Commit: d260d201ff4863628bf48af2f64a796cf58492ee
Parents: d66bf29
Author: Sudheer Vinukonda <[email protected]>
Authored: Mon Dec 22 17:14:00 2014 +0000
Committer: Leif Hedstrom <[email protected]>
Committed: Tue Dec 23 08:06:15 2014 -0700
----------------------------------------------------------------------
lib/perl/lib/Apache/TS/AdminClient.pm | 49 ++++++++++++++++--------------
1 file changed, 27 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d260d201/lib/perl/lib/Apache/TS/AdminClient.pm
----------------------------------------------------------------------
diff --git a/lib/perl/lib/Apache/TS/AdminClient.pm
b/lib/perl/lib/Apache/TS/AdminClient.pm
index 676ad74..1c2f0bd 100644
--- a/lib/perl/lib/Apache/TS/AdminClient.pm
+++ b/lib/perl/lib/Apache/TS/AdminClient.pm
@@ -28,7 +28,6 @@ use IO::Select;
use Apache::TS;
-
# Mgmt API command constants, should track ts/mgmtapi.h
use constant {
TS_FILE_READ => 0,
@@ -54,10 +53,9 @@ use constant {
TS_STATS_RESET => 20
};
-# We treat both REC_INT and REC_COUNTER the same here
use constant {
TS_REC_INT => 0,
- TS_REC_COUNTER => 0,
+ TS_REC_COUNTER => 1,
TS_REC_FLOAT => 2,
TS_REC_STRING => 3
};
@@ -204,29 +202,36 @@ sub get_stat {
return undef unless defined($self->{_socket});
return undef unless $self->{_select}->can_write(10);
-# This is a total hack for now, we need to wrap this into the proper mgmt API
library.
- $self->{_socket}->print(pack("sla*", TS_RECORD_GET, length($stat)), $stat);
+ # This is a total hack for now, we need to wrap this into the proper mgmt
API library.
+ # The request format is:
+ # MGMT_MARSHALL_INT: message length
+ # MGMT_MARSHALL_INT: TS_RECORD_GET
+ # MGMT_MARSHALL_STRING: record name
+ my $msg = pack("ll/Z", TS_RECORD_GET, $stat);
+ $self->{_socket}->print(pack("l/a", $msg));
$res = $self->_do_read();
- my @resp = unpack("slls", $res);
- return undef unless (scalar(@resp) == 4);
-
- if ($resp[0] == TS_ERR_OKAY) {
- if ($resp[3] < TS_REC_FLOAT) {
- @resp = unpack("sllsq", $res);
- return undef unless (scalar(@resp) == 5);
- return int($resp[4]);
+ # The response format is:
+ # MGMT_MARSHALL_INT: message length
+ # MGMT_MARSHALL_INT: error code
+ # MGMT_MARSHALL_INT: record type
+ # MGMT_MARSHALL_STRING: record name
+ # MGMT_MARSHALL_DATA: record data
+ ($msg) = unpack("l/a", $res);
+ my ($ecode, $type, $name, $value) = unpack("l l l/Z l/a", $msg);
+
+ if ($ecode == TS_ERR_OKAY) {
+ if ($type == TS_REC_INT || $type == TS_REC_COUNTER) {
+ my ($ival) = unpack("q", $value);
+ return $ival;
}
- elsif ($resp[3] == TS_REC_FLOAT) {
- @resp = unpack("sllsf", $res);
- return undef unless (scalar(@resp) == 5);
- return $resp[4];
+ elsif ($type == TS_REC_FLOAT) {
+ my ($fval) = unpack("f", $value);
+ return $fval;
}
- elsif ($resp[3] == TS_REC_STRING) {
- @resp = unpack("sllsa*", $res);
- return undef unless (scalar(@resp) == 5);
- my @result = split($stat, $resp[4]);
- return $result[0];
+ elsif ($type == TS_REC_STRING) {
+ my ($sval) = unpack("Z*", $value);
+ return $sval;
}
}