KeepAlive::IsAlive()

The only method of the KeepAlive class, IsAlive() is used in applications to request that the current command be terminated by disconnecting.

Virtual?

Yes

 

Class

KeepAlive

 

Arguments

None

 

Returns

int

0 to terminate connection, 1 to continue processing

Notes

Use ClientApi::SetBreak() to establish a callback to be called every 0.5 seconds during command execution.

See also

ClientApi::SetBreak()

Example

The following example implements a custom IsAlive() that can be called three times before returning 0 and terminating the connection. If the call to run the changes command takes less than 1.5 seconds to complete on the server side, the program outputs the list of changes. If the call to run the changes command takes more than 1.5 seconds, the connection is interrupted.

#include <clientapi.h>

// subclass KeepAlive to implement a customized IsAlive function.
class MyKeepAlive : public KeepAlive
{
    public:
    int  IsAlive();
};

// Set up the interrupt callback. After being called 3 times,
// interrupt 3 times, interrupt the current server operation.
int   MyKeepAlive::IsAlive()
{
    static int counter = 0;
    if ( ++counter > 3 )
    {
        counter = 0;
        return( 0 );
    }
    return( 1 );
}

// Now test the callback
ClientUser ui;
ClientApi client;
MyKeepAlive cb;
Error e;

client.Init( &e );
client.SetBreak( &cb );   // SetBreak must happen after the Init
client.Run( "changes", &ui );
client.Final( &e );