Repository: trafficserver Updated Branches: refs/heads/master 9115cb6d4 -> 2da4df4a6
[TS-3254] : patch from James to fix perl get_stats API Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/2da4df4a Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/2da4df4a Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/2da4df4a Branch: refs/heads/master Commit: 2da4df4a6726db55e3b8630d3599145708df8983 Parents: 9115cb6 Author: Sudheer Vinukonda <[email protected]> Authored: Mon Dec 22 17:14:00 2014 +0000 Committer: Sudheer Vinukonda <[email protected]> Committed: Mon Dec 22 17:14:00 2014 +0000 ---------------------------------------------------------------------- CHANGES | 2 ++ lib/perl/lib/Apache/TS/AdminClient.pm | 49 ++++++++++++++++-------------- 2 files changed, 29 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2da4df4a/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index f7c4126..9b05143 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.3.0 + *) [TS-3248] Fix with Susan's help to resolve crash introduced in TS-3189 + *) [TS-3255] support flush option in gzip plugins. *) [TS-3222] Fix port print to not have leading 0. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2da4df4a/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 3354e96..ab6fd03 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; } }
