ClientApi::SetBreak( KeepAlive *breakCallback )

Establish a callback that is called every 0.5 seconds during command execution.

Virtual?

No

 

Class

ClientApi

 

Arguments

KeepAlive *breakCallback

keepalive callback for user interrupt

Returns

void

 

Notes

To establish the callback routine, you must call SetBreak() after ClientApi::Init().

See also

KeepAlive::IsAlive()

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 server process receives an interrupt request.

#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 );