From 75ee7925a9e289bc24f0ce8a7988cca926b71513 Mon Sep 17 00:00:00 2001 From: Jan Zeleny Date: Aug 01 2012 14:19:41 +0000 Subject: Primary server support: introduce concept of reconnection This patch adds two support functions for adding reconnection callbacks and invoking such callbacks. The concept of reconnection is simple: stop using current connection for for new queries to the server without actually going offline. --- diff --git a/src/providers/data_provider_callbacks.c b/src/providers/data_provider_callbacks.c index 9d8946a..0f8fca0 100644 --- a/src/providers/data_provider_callbacks.c +++ b/src/providers/data_provider_callbacks.c @@ -141,6 +141,41 @@ static errno_t be_run_cb(struct be_ctx *be, struct be_cb *cb_list) { return EOK; } +int be_add_reconnect_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb, + void *pvt, struct be_cb **reconnect_cb) +{ + int ret; + + ret = be_add_cb(mem_ctx, ctx, cb, pvt, &ctx->reconnect_cb_list, reconnect_cb); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, ("be_add_cb failed.\n")); + return ret; + } + + return EOK; +} + +void be_run_reconnect_cb(struct be_ctx *be) +{ + struct be_cb *callback = be->reconnect_cb_list; + + if (callback) { + DEBUG(SSSDBG_TRACE_FUNC, ("Reconnecting. Running callbacks.\n")); + + /** + * Call the callback: we have to call this right away + * so the provider doesn't go into offline even for + * a little while + */ + do { + callback->cb(callback->pvt); + callback = callback->next; + } while(callback != NULL); + } else { + DEBUG(SSSDBG_TRACE_INTERNAL, ("Reconnect call back list is empty, nothing to do.\n")); + } +} + int be_add_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb, void *pvt, struct be_cb **online_cb) { diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h index 6496697..41dd3f6 100644 --- a/src/providers/dp_backend.h +++ b/src/providers/dp_backend.h @@ -107,6 +107,7 @@ struct be_ctx { struct be_cb *online_cb_list; bool run_online_cb; struct be_cb *offline_cb_list; + struct be_cb *reconnect_cb_list; struct be_offline_status offstat; @@ -186,6 +187,13 @@ struct be_host_req { bool be_is_offline(struct be_ctx *ctx); void be_mark_offline(struct be_ctx *ctx); +int be_add_reconnect_cb(TALLOC_CTX *mem_ctx, + struct be_ctx *ctx, + be_callback_t cb, + void *pvt, + struct be_cb **reconnect_cb); +void be_run_reconnect_cb(struct be_ctx *be); + int be_add_online_cb(TALLOC_CTX *mem_ctx, struct be_ctx *ctx, be_callback_t cb,