Is registering an Net-SNMP alarm the only way to delay a response?
I don't need to delay for a given amount of time, but until a signal is
received (sigc signal). Anyway I could do that?
If not, the only possible way I see to get around this is to use an alarm with
a timeout delay. Wait for 5-10 seconds, check if signal is received and data
ready and then send it to the requester, if not send error
SNMP_ERR_RESOURCEUNAVAILABLE .
My code for the delayed handler. I doesn't work if I keep the
snmp_alarm_register inside the for-loop. Why is that? It will fail on the line
with " if (!cache) { ".
Also, somehow handle_snmp gets called 4 times when delayed 1 second, 9 times
for 2 seconds, 14 times for 3 seconds. I can't have that. Inside my
if-statement in the for-loop I call my device to get the information for the
request, I cannot call this so many times for one only request.
[CODE]
int
handle_snmp(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
const oid* request_oid = (*reginfo).rootoid;
map<oid_wrapper, scalar>::iterator scalar_iterator;
for (scalar_iterator = scalars.begin();
scalar_iterator != scalars.end();
scalar_iterator++) {
const oid_wrapper oid_wrapper = (*scalar_iterator).first;
const scalar _scalar = (*scalar_iterator).second;
const oid* oid_value = oid_wrapper.get_oid();
const int oid_length = oid_wrapper.get_length();
if (netsnmp_oid_equals(oid_value, oid_length, request_oid, oid_length) == 0) {
cout << "We got here..." << endl;
requests->delegated = 1;
snmp_alarm_register(1,
0,
delayed_response,
(void *)
netsnmp_create_delegated_cache(handler,
reginfo,
reqinfo,
requests,
NULL));
} else {
netsnmp_set_request_error(reqinfo,
requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
}
return SNMP_ERR_NOERROR;
}
void
delayed_response(unsigned int clientreg, void *clientarg) {
netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) clientarg;
netsnmp_request_info *requests;
netsnmp_agent_request_info *reqinfo;
cache = netsnmp_handler_check_cache(cache);
if (!cache) {
snmp_log(LOG_ERR, "illegal call to return delayed response\n");
return;
}
reqinfo = cache->reqinfo;
requests = cache->requests;
void* datapointer;
char buffer[2048];
int dataint;
int length = 0;
u_char type;
strcpy(buffer, "Testing delayed SNMP");
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
requests->delegated = 0;
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb,
type,
datapointer,
length);
break;
default:
snmp_log(LOG_ERR, "unknown mode (%d) in delayed_response\n", reqinfo->mode );
}
netsnmp_free_delegated_cache(cache);
}
[/CODE]
CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users