6.5   Asynchronous Method Routines

Method routines can be written to behave asynchronously from the SNMP agent. In this case, the method routine spawns a task to complete the requested activities, and the method routine returns before the task completes.


*   

NOTE: The processing of a single message from an SNMP master may require the execution of several method routines. As mentioned above, it is possible for the SNMP agent to run these method routines asynchronously. However, this does not make the SNMP agent asynchronous with respect to the SNMP manager. The SNMP agent processes messages from the SNMP manager synchronously. Thus, it does not accept a new message until it has completed processing for the last message.

The method routine must first lock the packet in question using snmpdPktLockGet( ), and call the appropriate process mechanism depending on the type of operation (getproc_started( ), nextproc_started( ), or setproc_started( )) to indicate that the activity has begun.

When the task completes, which is again indicatedwith a call to the appropriate process mechanism (getproc_good( ), nextproc_good( ), or setproc_good( )), the routine must call snmpdContinue( ) to complete processing of the packet and issue the response.

For more information on process mechanisms, see the manual pages for snmpProcLib and for the individual process routines in F. SNMP Reference. Also see the manual pages for snmpdPktLockGet( ) and snmpdContinue( ) in the same section.

Example 6-10:  Asynchronous Method Routine

groupGet 
    ( 
    OIDC_T              lastmatch, 
    int                 compc, 
    OIDC_T *            compl, 
    SNMP_PKT_T *        pktp, 
    VB_T *              vbp 
    ) 
    { 
 
    snmpdGroupByGetprocAndInstance (pktp, vbp, compc, compl); 
 
    if ( (compc != 1) || (*compl != 0) )  
        { 
        for ( ; vbp != NULL; vbp = vbp->vb_link) 
            { 
            getproc_nosuchins (pktp, vbp); 
            } 
        return; 
        } 
 
    /* At this stage we are ready to spawn an asynchronous task that will 
       continue withe the job of getting the vars and installing those 
       values in the response pkt. However we must first indicate to the 
       agent that the getproc for all these varbinds has been started, 
       else the agent could start them again */ 
 
    for (vbp = pVbpSaved ; vbp != NULL; vbp = vbp->vb_link) 
            { 
            getproc_started (pktp, vbp); 
            } 
 
    /* Now spawn the asynch routine */ 
 
    status = taskSpawn (asyncRtn, ...); 
 
    if (status != OK) 
        { 
        for (vbp = pVbpSaved ; vbp != NULL; vbp = vbp->vb_link) 
            { 
            getproc_error (pktp, vbp); 
            return; 
            } 
        } 
   
    return; 
 
    } 
 
 
void asyncRtn 
    ( 
    OIDC_T              lastmatch, 
    int                 compc, 
    OIDC_T *            compl, 
    SNMP_PKT_T *        pktp, 
    VB_T *              vbp 
    ) 
    { 
 
     /* time consumng tasks done here */ 
      ..... 
 
     /* after doing all the time consuming  tasks we are now ready to 
        install the values in the pkt. */ 
 
     snmpdPktLockGet (pktp); 
       
     for (vbp = pVbpSaved ; vbp != NULL; vbp = vbp->vb_link) 
            { 
             /* Do whatever steps are reqd to install the var bind value  
                as in the synchronous method routines */ 
 
             ...... 
 
             } 
 
     snmpdContinue (pktp); 
     }