of the *_send() signature.
uint32_t pnn;
ctdb_handle *handle;
- handle = ctdb_getpnn_send(ctdb, destnode);
+ handle = ctdb_getpnn_send(ctdb, destnode, NULL, NULL);
if (handle == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to send getpnn control\n"));
return -1;
* The exception is when called from in the registered callback,
* in this case the fucntion is guaranteed not to block.
*
- * 2, Registering an async callback to be invoked when the call completes.
+ * 2, providing an async callback to be invoked when the call completes.
* From inside the callback you use the *_recv() function to extract the
* response data.
*
typedef void ctdb_handle;
-/*
- * After issuing a *_send() command, you can use this function to register a
- * a callback function to be automatically called once the call
- * finishes.
- *
- * Once the callback function returns, the handle will be automatically
- * destroyed.
- *
- * If using ctdb_free() to abort a call in flight, you have to take care
- * to avoid the race condition that would exist between the callback and
- * ctdb_free().
- *
- * Possible method could be :
- * * take pthreads mutex
- * * ctdb_set_callback(handle, NULL, NULL)
- * * verify that the callback has not yet been called
- * (if it has handle is no longer valid)
- * * ctdb_free(handle)
- * * release pthreads mutex
- */
-typedef void (*ctdb_callback)(int32_t status, struct ctdb_context *ctdb, ctdb_handle *, void *private_data);
-
-int ctdb_set_callback(ctdb_handle *handle, ctdb_callback callback, void *private_data);
-
-
+typedef void (*ctdb_generic_callback)(int32_t status, struct ctdb_context *ctdb, ctdb_handle *, void *private_data);
/*
*/
ctdb_handle *
ctdb_getpnn_send(struct ctdb_context *ctdb,
- uint32_t destnode);
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data);
int ctdb_getpnn_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
uint32_t *pnn);
/*
* functions to read the recovery master of a node
*/
-typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
-
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
- uint32_t destnode);
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data);
int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
uint32_t *recmaster);
/*
- * cancel a request/call
+ * cancel a request/call or release a resource
*/
int ctdb_free(ctdb_handle *);
ctdb_control_cb(struct ctdb_client_control_state *state)
{
struct ctdb_control_cb_data *cb_data = state->async.private_data;
- ctdb_callback callback = (ctdb_callback)cb_data->callback;
+ ctdb_generic_callback callback = (ctdb_generic_callback)cb_data->callback;
/* dont recurse */
state->async.fn = NULL;
/*
* This function is used to set the callback action for a handle
*/
-int ctdb_set_callback(ctdb_handle *handle, ctdb_callback callback, void *private_data)
+static int
+ctdb_set_generic_callback(ctdb_handle *handle, ctdb_generic_callback callback, void *private_data)
{
struct ctdb_client_control_state *control_state = talloc_get_type(handle, struct ctdb_client_control_state);
*************************/
ctdb_handle *
ctdb_getpnn_send(struct ctdb_context *ctdb,
- uint32_t destnode)
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data)
{
struct ctdb_client_control_state *state;
return NULL;
}
+ if (callback != NULL) {
+ ctdb_set_generic_callback(state, callback, private_data);
+ }
+
return (ctdb_handle *)state;
}
{
struct ctdb_client_control_state *state;
- state = ctdb_getpnn_send(ctdb, destnode);
+ state = ctdb_getpnn_send(ctdb, destnode, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getpnn_send() failed.\n"));
return -1;
***********************/
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
- uint32_t destnode)
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data)
{
struct ctdb_client_control_state *state;
return NULL;
}
+ if (callback != NULL) {
+ ctdb_set_generic_callback(state, callback, private_data);
+ }
+
return (ctdb_handle *)state;
}
{
struct ctdb_client_control_state *state;
- state = ctdb_getrecmaster_send(ctdb, destnode);
+ state = ctdb_getrecmaster_send(ctdb, destnode, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getrecmaster_send() failed.\n"));
return -1;
* ASYNC call with callback to read the recmaster
* this is the preferred way to use libctdb
*/
- handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE, rm_cb, NULL);
if (handle == NULL) {
printf("Failed to send get_recmaster control\n");
exit(10);
}
- ret = ctdb_set_callback(handle, rm_cb, NULL);
- if (ret != 0) {
- printf("Failed to set callback for get_recmaster\n");
- ctdb_free(handle);
- exit(10);
- }
/*
* SEMI-SYNC call with callback to read the recmaster
* calls the blocking *_recv() function.
* Avoid this mode for performance critical tasks
*/
- handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE, NULL, NULL);
if (handle == NULL) {
printf("Failed to send get_recmaster control\n");
exit(10);
- handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE, pnn_cb, NULL);
if (handle == NULL) {
printf("Failed to send get_pnn control\n");
exit(10);
}
- ret = ctdb_set_callback(handle, pnn_cb, NULL);
- if (ret != 0) {
- printf("Failed to set callback for getpnn\n");
- ctdb_free(handle);
- exit(10);
- }
+
handle = ctdb_readrecordlock_send(ctdb, ctdb_db_context, key, rrl_cb, NULL);