ClientApi::Dropped()
Check if connection is no longer usable.
Virtual? |
No |
|
Class |
||
Arguments |
None |
|
Returns |
|
nonzero if the connection has dropped |
Notes
Dropped()
is usually
called after Run()
; it then
checks whether the command completed successfully. If the Init()
is only followed by
one Run()
, as in
p4api.cc
, calling Final()
and then checking
the Error
is sufficient to see whether the connection was
dropped. However, if you plan to make many calls to Run()
after one call to Init()
, Dropped()
provides a way
to check that the commands are completing without actually cleaning up
the connection with Final()
.
Example
The Dropped()
method
is useful if you want to reuse a client connection multiple times, and
need to make sure that the connection is still alive.
For example, an application for stress-testing a Helix Server might run "p4 have
" 10,000 times or until the
connection dies:
ClientApi client; MyClientUser ui; //this ClientUser subclass doesn't output anything. Error e; client.Init( &e ); int count = 0; while ( !( client.Dropped() ) && count < 10000 ) { count++; client.Run( "have", &ui ); } printf( "Checked have list %d times.\n", count ); client.Final( &e ); // Clean up connection.
If the Dropped()
result is true, the while
loop ends. The actual error
message remains inaccessible until after the call to client.Final()
to close
the connection and store the error.