Condividi tramite


Usare un elenco di route Client-Specific

Le procedure seguenti illustrano i passaggi per usare gli elenchi di route specifici del client. Il codice di esempio che segue illustra come implementare la procedura.

Per usare questa funzionalità, un client deve eseguire la procedura seguente

  1. Chiamare RtmCreateRouteList per ottenere un handle dalla gestione tabelle di routing.
  2. Chiamare RtmInsertInRouteList ogni volta che il client deve aggiungere una route a questo elenco.
  3. Quando il client non richiede più l'elenco, deve chiamare RtmDeleteRouteList per rimuovere l'elenco.

Se il client deve enumerare le route nell'elenco, il client deve seguire questa procedura

  1. Chiamare RtmCreateRouteListEnum per ottenere un handle di enumerazione dalla gestione tabelle di routing.
  2. Chiamare RtmGetListEnumRoutes per ottenere gli handle per le route nell'elenco.
  3. Chiamare RtmReleaseRoutes per rilasciare gli handle quando non è più necessario.

Il codice di esempio seguente illustra come creare e usare un elenco di route specifico del client.

HANDLE RouteListHandle1;
HANDLE RouteListHandle2;

// Create two entity-specific lists to add routes to

Status = RtmCreateRouteList(RtmRegHandle,
                            &RouteListHandle1);
// Check Status
//...

Status = RtmCreateRouteList(RtmRegHandle,
                            &RouteListHandle2);
// Check Status
//...

// Assume you have added a bunch of routes
// by calling RtmAddRouteToDest many times
// with 'RouteListHandle1' specified similar to
// Status = RtmAddRouteToDest(RtmRegHandle,
//                            ...
//                            RouteListHandle1,
//                            ...
//                            &ChangeFlags);

// Enumerate routes in RouteListHandle1 list

// Create an enumeration on the route list

Status = RtmCreateRouteListEnum(RtmRegHandle,
                                RouteListHandle1,
                                &EnumHandle);

if (Status == NO_ERROR)
{
        // Allocate space on the top of the stack
        
    MaxHandles = RegnProfile.MaxHandlesInEnum;

    RouteHandles = _alloca(MaxHandles * sizeof(HANDLE));

    // Note how the termination condition is different
    // from other enumerations - the call to the function
    // RtmGetListEnumRoutes always returns NO_ERROR
    // Quit when you get fewer handles than requested
    
    do
    {
                // Get next set of routes from the list enumeration
        
        NumHandles = MaxHandles;

        Status = RtmGetListEnumRoutes(RtmRegHandle,
                                      EnumHandle,
                                      &NumHandles,
                                      RouteHandles);

        for (i = 0; i < NumHandles; i++)
        {
            Print("Route Handle %5lu: %p\n", i, RouteHandles[i]);
        }

        // Move all these routes to another route list
        // They are automatically removed from the old one
        
        Status = RtmInsertInRouteList(RtmRegHandle,
                                      RouteListHandle2,
                                      NumHandles,
                                      RouteHandles);
        // Check Status...
        
                // Release the routes that have been enumerated
        
        RtmReleaseRoutes(RtmRegHandle, NumHandles, RouteHandles);
    }
    while (NumHandles == MaxHandles);

    RtmDeleteEnumHandle(RtmRegHandle, EnumHandle);
}

// Destroy all the entity-specific route lists 
// after removing all routes from these lists;
// the routes themselves are not deleted

Status = RtmDeleteRouteList(RtmRegHandle, RouteListHandle1);
ASSERT(Status == NO_ERROR);


Status = RtmDeleteRouteList(RtmRegHandle, RouteListHandle2);
ASSERT(Status == NO_ERROR);