GError * peer_restore(const gchar *target, struct sqlx_name_s *name, GByteArray *dump) { GError *err = NULL; if (!target) { g_byte_array_unref(dump); return NULL; } GByteArray *encoded = _pack_RESTORE(name, dump); struct gridd_client_s *client = gridd_client_create(target, encoded, NULL, NULL); g_byte_array_unref(encoded); if (!client) return NEWERROR(CODE_INTERNAL_ERROR, "Failed to create client to [%s], bad address?", target); gridd_client_set_timeout(client, SQLX_RESYNC_TIMEOUT); gridd_client_start(client); if (!(err = gridd_client_loop(client))) err = gridd_client_error(client); gridd_client_free(client); return err; }
GError * gridd_client_exec_and_concat (const gchar *to, gdouble seconds, GByteArray *req, GByteArray **out) { if (!to) { g_byte_array_unref (req); return NEWERROR(CODE_INTERNAL_ERROR, "No target"); } GByteArray *tmp = NULL; if (out) tmp = g_byte_array_new(); struct gridd_client_s *client = gridd_client_create(to, req, out ? tmp : NULL, out ? (client_on_reply)_cb_exec_and_concat : NULL); g_byte_array_unref (req); if (!client) { if (tmp) g_byte_array_free (tmp, TRUE); return NEWERROR(CODE_INTERNAL_ERROR, "client creation"); } if (seconds > 0.0) gridd_client_set_timeout (client, seconds); GError *err = gridd_client_run (client); gridd_client_free (client); if (!err && out) { *out = tmp; tmp = NULL; } if (tmp) metautils_gba_unref (tmp); return err; }
static struct gridd_client_s * _factory_create_client (struct gridd_client_factory_s *factory) { EXTRA_ASSERT(factory != NULL); EXTRA_ASSERT(factory->abstract.vtable == &VTABLE_FACTORY); (void) factory; struct gridd_client_s *client = gridd_client_create_empty(); if (!client) return NULL; gridd_client_set_timeout(client, COMMON_CLIENT_TIMEOUT); return client; }
GError * gridd_client_exec4 (const gchar *to, gdouble seconds, GByteArray *req, GByteArray ***out) { if (!to) { g_byte_array_unref (req); return NEWERROR(CODE_INTERNAL_ERROR, "No target"); } GPtrArray *tmp = NULL; if (out) tmp = g_ptr_array_new(); struct gridd_client_s *client = gridd_client_create(to, req, (out ? tmp : NULL), out ? (client_on_reply)_cb_exec4 : NULL); g_byte_array_unref (req); if (!client) { if (tmp) g_ptr_array_free (tmp, TRUE); return NEWERROR(CODE_INTERNAL_ERROR, "client creation"); } if (seconds > 0.0) gridd_client_set_timeout (client, seconds); GError *err = gridd_client_run (client); gridd_client_free (client); if (!err && out) { *out = (GByteArray**) metautils_gpa_to_array (tmp, TRUE); tmp = NULL; } if (tmp) { g_ptr_array_set_free_func (tmp, (GDestroyNotify)g_byte_array_unref); g_ptr_array_free (tmp, TRUE); tmp = NULL; } return err; }
void gridd_clients_set_timeout(struct client_s **clients, gdouble to0, gdouble to1) { for (; *clients ;++clients) gridd_client_set_timeout(*clients, to0, to1); }
void gridd_clients_set_timeout(struct gridd_client_s **clients, gdouble seconds) { for (; *clients ;++clients) gridd_client_set_timeout(*clients, seconds); }