SNMP Subagent Programmer's Guide
Programming Tutorials
SNMP Subagent Programmer’s Guide—119728 2-29
Fault-Tolerant Hello World Program
Source Code
The Fault-Tolerant Hello World source code appears in Example 2-4. Numbers in the
example correspond to comments in the discussions located between here and the
example.
Global Declarations
Declarations are set up to handle simultaneous communication with multiple NonStop
agents:
1. A structure is declared to hold three values for each NonStop agent connection.
2. An array named agent_info is defined for keeping track of as many as five NonStop
agent connections.
Main Control Block
This logic manages connections with all the agent processes named at invocation:
3. A counter named living_agent_count is defined for determining whether any
NonStop agent connections currently exist.
4. This “for” loop initializes the agent_info array for each NonStop agent specified,
performing the following four steps.
5. The mgmt_init_env() management function is called.
6. The mgmt_new_instance() function is called.
7. An SNMP message buffer is allocated.
8. A nowaited read for the NonStop agent is posted.
9. This loop consists of a block called “wait,” which detects and analyzes I/O
operations and processes SNMP messages. It terminates when all NonStop agent
connections have terminated and living_agent_count has therefore reached 0.
10. The Guardian AWAITIOX procedure detects any I/O completions or timeouts.
11. The Guardian FILE_GETINFO_ procedure determines the cause of an incomplete I/
O operation. As in the case of Nowaited Hello World, the current value of
helloOutputText is printed when a timeout occurs.
12. If an erroneous I/O operation involves one of the NonStop agents, the connection
with that agent is marked invalid by assigning -1 to its file number.
13. When an I/O operation involving a NonStop agent completes, this “for” loop
processes the message.
14. If mgmt_poll() fails, the agent connection is marked invalid.
15. Trap and message processing proceed.
16. The mgmt_read_nowait() management function is called to reestablish a read with
the NonStop agent. If it fails, the agent connection is marked invalid.