SNMP Subagent Programmer's Guide

Management Functions
4-16 119728—SNMP Subagent Programmer’s Guide
Writing Subagent Logic
Examples
The following example is from the Hello World sample program. Because it uses a
blocking mgmt_poll() call, this program is idle until a request arrives from the NonStop
agent. Then, mgmt_poll() processes the request, and the subagent calls mgmt_poll()
again, blocking until another request is received:
while (!time_to_die)
{
if (mgmt_poll(mgmt_env, (struct timeval *) NULL,
&dummy) < 0)
{
(void) fputs(argv[0], stderr);
(void) fputs(": agent unavailable\n", stderr);
break;
}
Nowaited Hello World also uses a blocking mgmt_poll() call, but only calls mgmt_poll()
when the NonStop agent has sent the subagent a message to process. This subagent uses
management function mgmt_read_nowait() to post a nowaited read to the NonStop
agent. The subagent is then free to do other work while waiting for requests to arrive.
To detect when any I/O operation has been completed, the subagent calls Guardian
procedure AWAITIOX. AWAITIOX returns the file number for which the operation
completed to event_fileno and the number of bytes received to count_xferd:
agent_fileno = mgmt_read_nowait
((struct mgmt_env*)mgmt_env,NULL);
...
status = AWAITIOX(&event_fileno,,&count_xferd,,
100*helloPrintFreq);
...
if (event_fileno == agent_fileno) {
if (mgmt_poll((struct mgmt_env *) mgmt_env,
(struct timeval *) NULL,
&count_xferd) <0) }
The Indexed Trap Generator uses a blocking mgmt_poll() call to detect when the
NonStop agent has acknowledged its object registration. The waited call is included so
that an attempt to send a trap does not occur before the NonStop agent is ready to
process it. This subagent also uses a nonblocking mgmt_poll() call to determine
whether a request is available for processing. The call does not block because the
timeval structure is filled in with 0s before calling mgmt_poll():
wait.tv_sec = 0;
wait.tv_usec = 0;
if (mgmt_poll(mgmt_env, &wait, &dummy) < 0)
The mgmt_poll() function determines whether the NonStop agent has a request to
process. If there is no request pending, control returns to the subagent immediately. If a
request is pending, it is processed before control returns to the subagent.