| 1 |
fb_cancel_operation() - new API call in firebird 2.5. |
| 2 |
|
| 3 |
Implements capability to asynchronously cancel long running API call. |
| 4 |
|
| 5 |
Author: |
| 6 |
Alex Peshkoff <[email protected]> |
| 7 |
|
| 8 |
Syntax is: |
| 9 |
|
| 10 |
ISC_STATUS fb_cancel_operation(ISC_STATUS* status_vector, |
| 11 |
isc_db_handle* db_handle, |
| 12 |
ISC_USHORT option); |
| 13 |
|
| 14 |
Description: |
| 15 |
|
| 16 |
Action performed by this function depends upon value of last parameter, option. Option can be: |
| 17 |
- fb_cancel_raise: cancels any activity, related with db_handle. This means that firebird |
| 18 |
will as soon as possible (to be precise, at the nearest rescheduling point, except some special |
| 19 |
states of engine) try to stop running request and error-return to the user. |
| 20 |
- fb_cancel_disable: disable execution of fb_cancel_raise requests for given attachment. It's |
| 21 |
useful when your program executes some critical things (for example, cleanup). |
| 22 |
- fb_cancel_enable: enables previously disabled cancel delivery. |
| 23 |
- fb_cancel_abort: forcible close client side of connection. Useful if you need to close |
| 24 |
connection urgently. All active transactions will be rolled back by server. Success always |
| 25 |
returned to the application. Use with care ! |
| 26 |
|
| 27 |
fb_cancel_disable / fb_cancel_enable may be set many times - if engine is already in requested |
| 28 |
state, no action is taken. Cancel is enabled by default (i.e. after attach/create database). |
| 29 |
|
| 30 |
Pay attention to asynchronous nature of this API call. Usually fb_cancel_raise is called when |
| 31 |
you need to stop long-running request. This means that it's called from separate thread (calling |
| 32 |
it from signal handler is bad idea, it's NOT async signal safe). Another side of asynchronous |
| 33 |
execution is that at the end of API call attachment's activity may be already cancelled, may be not |
| 34 |
(and the second is very possible). It also means that returned status vector will almost always be |
| 35 |
FB_SUCCESS, though some errors are possible (like error sending network packet to remote server). |
| 36 |
|
| 37 |
Sample: |
| 38 |
|
| 39 |
Thread A: |
| 40 |
fb_cancel_operation(isc_status, &DB, fb_cancel_enable); |
| 41 |
isc_dsql_execute_immediate(isc_status, &DB, &TR, 0, "long running statement", 3, NULL); |
| 42 |
// waits for API call to finish... |
| 43 |
|
| 44 |
Thread B: |
| 45 |
fb_cancel_operation(local_status, &DB, fb_cancel_raise); |
| 46 |
|
| 47 |
Thread A: |
| 48 |
if (isc_status[1]) |
| 49 |
isc_print_status(isc_status); // will print "operation was cancelled" |