/** * @brief Removes a session from the session list of the connection. */ static void cl_conn_remove_session(sr_conn_ctx_t *connection, sr_session_ctx_t *session) { sr_session_list_t *tmp = NULL, *prev = NULL; CHECK_NULL_ARG_VOID2(connection, session); pthread_mutex_lock(&connection->lock); /* find matching session in linked list */ tmp = connection->session_list; while ((NULL != tmp) && (tmp->session != session)) { prev = tmp; tmp = tmp->next; } /* remove the session from linked-list */ if (NULL != tmp) { if (NULL != prev) { /* tmp is NOT the first item in list - skip it */ prev->next = tmp->next; } else if (NULL != tmp->next) { /* tmp is the first, but not last item in list - skip it */ connection->session_list = tmp->next; } else { /* tmp is the only item in the list */ connection->session_list = NULL; } free(tmp); } else { SR_LOG_WRN("Session %p not found in session list of connection.", (void*)session); } pthread_mutex_unlock(&connection->lock); }
/** * @brief Callback called by the event loop watcher when init retry timer expires. */ static void sr_pd_init_retry_timer_cb(struct ev_loop *loop, ev_timer *w, int revents) { sr_pd_ctx_t *ctx = NULL; bool init_retry_needed = false; int rc = SR_ERR_OK; CHECK_NULL_ARG_VOID2(w, w->data); ctx = (sr_pd_ctx_t*)w->data; CHECK_NULL_ARG_VOID(ctx); for (size_t i = 0; i < ctx->plugins_cnt; i++) { if (! ctx->plugins[i].initialized) { rc = sr_pd_init_plugin(ctx->session, &(ctx->plugins[i])); if (SR_ERR_OK != rc) { init_retry_needed = true; } } } if (!init_retry_needed) { ev_timer_stop(ctx->event_loop, &ctx->init_retry_timer); } else { SR_LOG_DBG("Scheduling plugin init retry after %d seconds.", SR_PLUGIN_INIT_RETRY_TIMEOUT); } }
/** * @brief Callback called by the event loop watcher when health check timer expires. */ static void sr_pd_health_check_timer_cb(struct ev_loop *loop, ev_timer *w, int revents) { sr_pd_ctx_t *ctx = NULL; bool init_retry_needed = false; int rc = SR_ERR_OK; CHECK_NULL_ARG_VOID2(w, w->data); ctx = (sr_pd_ctx_t*)w->data; CHECK_NULL_ARG_VOID(ctx); for (size_t i = 0; i < ctx->plugins_cnt; i++) { if (ctx->plugins[i].initialized && (NULL != ctx->plugins[i].health_check_cb)) { rc = ctx->plugins[i].health_check_cb(ctx->session, ctx->plugins[i].private_ctx); if (SR_ERR_OK != rc) { SR_LOG_ERR("Health check of the plugin '%s' returned an error: %s", ctx->plugins[i].filename, sr_strerror(rc)); sr_pd_cleanup_plugin(ctx, &(ctx->plugins[i])); init_retry_needed = true; } } } if (init_retry_needed) { SR_LOG_DBG("Scheduling plugin init retry after %d seconds.", SR_PLUGIN_INIT_RETRY_TIMEOUT); ev_timer_start(ctx->event_loop, &ctx->init_retry_timer); } }
/** * @brief Callback called by the event loop watcher when a signal is caught. */ static void sr_pd_signal_cb(struct ev_loop *loop, struct ev_signal *w, int revents) { CHECK_NULL_ARG_VOID2(loop, w); SR_LOG_DBG("Signal %d caught, breaking the event loop.", w->signum); ev_break(loop, EVBREAK_ALL); }
/** * @brief Cleans up the provided plugin. */ static void sr_pd_cleanup_plugin(sr_pd_ctx_t *ctx, sr_pd_plugin_ctx_t *plugin) { CHECK_NULL_ARG_VOID2(ctx, plugin); if (plugin->initialized) { plugin->cleanup_cb(ctx->session, plugin->private_ctx); plugin->initialized = false; } }