ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-SNMP-XS/XS.pm
Revision: 1.7
Committed: Sat Apr 11 04:22:49 2009 UTC (15 years, 1 month ago) by root
Branch: MAIN
CVS Tags: rel-0_02
Changes since 1.6: +2 -4 lines
Log Message:
0.02

File Contents

# Content
1 =head1 NAME
2
3 Net::SNMP::XS - speed up Net::SNMP by decoding in XS, with limitations
4
5 =head1 SYNOPSIS
6
7 use Net::SNMP::XS;
8
9 # loading it is enough, there are no public symbols
10
11 =head1 DESCRIPTION
12
13 This module tries to speed up Net::SNMP response packet decoding.
14
15 It does this by overriding a few selected internal method by (almost)
16 equivalent XS methods.
17
18 This currently reduces decode time by a factor of ten for typical bulk
19 responses.
20
21 There are currently the following limitations when using this module:
22
23 =over 4
24
25 =item overriding internal functions might cause the module to
26 malfunction with future versions of Net::SNMP
27
28 =item only leading dots for oids are supported
29
30 =item error messages will be simpler/different
31
32 =item oid components are limited to unsigned 32 bit integers
33
34 =item translation will be ignored (all values will be delivered "raw")
35
36 =item a moderately modern (>= C99) C compiler is required
37
38 =item only tested with 5.10, no intentions to port to older perls
39
40 =item duplicate OIDs are not supported
41
42 =item REPORT PDUs are not supported
43
44 =back
45
46 =cut
47
48 package Net::SNMP::XS;
49
50 use strict qw(vars subs);
51 no warnings;
52
53 use Guard;
54
55 use Net::SNMP::PDU ();
56 use Net::SNMP::Message ();
57 use Net::SNMP::MessageProcessing ();
58
59 our $VERSION;
60 our $old_prepare;
61
62 BEGIN {
63 $VERSION = '0.02';
64
65 $old_prepare = \&Net::SNMP::MessageProcessing::prepare_data_elements;
66
67 # this overrides many methods inside
68 require XSLoader;
69 XSLoader::load Net::SNMP::XS, $VERSION;
70 }
71
72 sub Net::SNMP::MessageProcessing::prepare_data_elements {
73 my ($self, $msg) = @_;
74
75 set_msg $msg, $msg->{_buffer};
76 scope_guard \&clr_msg;
77 &$old_prepare
78 }
79
80 {
81 package Net::SNMP::Message;
82
83 Net::SNMP::XS::set_type INTEGER , \&_process_integer32;
84 Net::SNMP::XS::set_type OCTET_STRING , \&_process_octet_string;
85 Net::SNMP::XS::set_type NULL , \&_process_null;
86 Net::SNMP::XS::set_type OBJECT_IDENTIFIER, \&_process_object_identifier;
87 Net::SNMP::XS::set_type SEQUENCE , \&_process_sequence;
88 Net::SNMP::XS::set_type IPADDRESS , \&_process_ipaddress;
89 Net::SNMP::XS::set_type COUNTER , \&_process_counter;
90 Net::SNMP::XS::set_type GAUGE , \&_process_gauge;
91 Net::SNMP::XS::set_type TIMETICKS , \&_process_timeticks;
92 Net::SNMP::XS::set_type OPAQUE , \&_process_opaque;
93 Net::SNMP::XS::set_type COUNTER64 , \&_process_counter64;
94 Net::SNMP::XS::set_type NOSUCHOBJECT , \&_process_nosuchobject;
95 Net::SNMP::XS::set_type NOSUCHINSTANCE , \&_process_nosuchinstance;
96 Net::SNMP::XS::set_type ENDOFMIBVIEW , \&_process_endofmibview;
97 Net::SNMP::XS::set_type GET_REQUEST , \&_process_get_request;
98 Net::SNMP::XS::set_type GET_NEXT_REQUEST , \&_process_get_next_request;
99 Net::SNMP::XS::set_type GET_RESPONSE , \&_process_get_response;
100 Net::SNMP::XS::set_type SET_REQUEST , \&_process_set_request;
101 Net::SNMP::XS::set_type TRAP , \&_process_trap;
102 Net::SNMP::XS::set_type GET_BULK_REQUEST , \&_process_get_bulk_request;
103 Net::SNMP::XS::set_type INFORM_REQUEST , \&_process_inform_request;
104 Net::SNMP::XS::set_type SNMPV2_TRAP , \&_process_v2_trap;
105 Net::SNMP::XS::set_type REPORT , \&_process_report;
106 }
107
108 1;
109
110 =head1 AUTHOR
111
112 Marc Lehmann <schmorp@schmorp.de>
113 http://home.schmorp.de/
114
115 =cut
116