aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/plugin_datastore_postgres.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2015-03-21 03:38:29 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2015-03-21 03:38:29 +0000
commitc77d4e5c69ac54ffddf5bd60c18bcb0504389311 (patch)
treebb40b73db6ed428d6ab44ffee91ca0ed6f16b592 /src/datastore/plugin_datastore_postgres.c
parentce6f1156a58aafed6563585b3be560ec0b4eabe7 (diff)
Convert datastore plugin API to asynchronous
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r--src/datastore/plugin_datastore_postgres.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c
index eb2a69c277..e0decc0243 100644
--- a/src/datastore/plugin_datastore_postgres.c
+++ b/src/datastore/plugin_datastore_postgres.c
@@ -279,15 +279,16 @@ postgres_plugin_estimate_size (void *cls, unsigned long long *estimate)
* @param anonymity anonymity-level for the content
* @param replication replication-level for the content
* @param expiration expiration time for the content
- * @param msg set to error message
- * @return #GNUNET_OK on success
+ * @param cont continuation called with success or failure status
+ * @param cont_cls continuation closure
*/
-static int
+static void
postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
const void *data, enum GNUNET_BLOCK_Type type,
uint32_t priority, uint32_t anonymity,
uint32_t replication,
- struct GNUNET_TIME_Absolute expiration, char **msg)
+ struct GNUNET_TIME_Absolute expiration, PluginPutCont cont,
+ void *cont_cls)
{
struct Plugin *plugin = cls;
struct GNUNET_HashCode vhash;
@@ -326,12 +327,15 @@ postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz
paramFormats, 1);
if (GNUNET_OK !=
GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put"))
- return GNUNET_SYSERR;
+ {
+ cont (cont_cls, key, size, GNUNET_SYSERR, _("Postgress exec failure"));
+ return;
+ }
PQclear (ret);
plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres",
"Stored %u bytes in database\n", (unsigned int) size);
- return GNUNET_OK;
+ cont (cont_cls, key, size, GNUNET_OK, NULL);
}
@@ -753,12 +757,13 @@ postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc,
* @param expire new expiration time should be the
* MAX of any existing expiration time and
* this value
- * @param msg set to error message
- * @return GNUNET_OK on success
+ * @param cont continuation called with success or failure status
+ * @param cons_cls continuation closure
*/
-static int
+static void
postgres_plugin_update (void *cls, uint64_t uid, int delta,
- struct GNUNET_TIME_Absolute expire, char **msg)
+ struct GNUNET_TIME_Absolute expire,
+ PluginUpdateCont cont, void *cont_cls)
{
struct Plugin *plugin = cls;
PGresult *ret;
@@ -783,9 +788,12 @@ postgres_plugin_update (void *cls, uint64_t uid, int delta,
paramFormats, 1);
if (GNUNET_OK !=
GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update"))
- return GNUNET_SYSERR;
+ {
+ cont (cont_cls, GNUNET_SYSERR, NULL);
+ return;
+ }
PQclear (ret);
- return GNUNET_OK;
+ cont (cont_cls, GNUNET_OK, NULL);
}
@@ -819,6 +827,7 @@ postgres_plugin_get_keys (void *cls,
}
}
PQclear (res);
+ proc (proc_cls, NULL, 0);
}