diff options
author | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
---|---|---|
committer | David Barksdale <amatus.amongus@gmail.com> | 2015-03-21 03:38:29 +0000 |
commit | c77d4e5c69ac54ffddf5bd60c18bcb0504389311 (patch) | |
tree | bb40b73db6ed428d6ab44ffee91ca0ed6f16b592 /src/datastore/plugin_datastore_postgres.c | |
parent | ce6f1156a58aafed6563585b3be560ec0b4eabe7 (diff) | |
download | gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.tar.gz gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.zip |
Convert datastore plugin API to asynchronous
Diffstat (limited to 'src/datastore/plugin_datastore_postgres.c')
-rw-r--r-- | src/datastore/plugin_datastore_postgres.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/datastore/plugin_datastore_postgres.c b/src/datastore/plugin_datastore_postgres.c index eb2a69c27..e0decc024 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) | |||
279 | * @param anonymity anonymity-level for the content | 279 | * @param anonymity anonymity-level for the content |
280 | * @param replication replication-level for the content | 280 | * @param replication replication-level for the content |
281 | * @param expiration expiration time for the content | 281 | * @param expiration expiration time for the content |
282 | * @param msg set to error message | 282 | * @param cont continuation called with success or failure status |
283 | * @return #GNUNET_OK on success | 283 | * @param cont_cls continuation closure |
284 | */ | 284 | */ |
285 | static int | 285 | static void |
286 | postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, | 286 | postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t size, |
287 | const void *data, enum GNUNET_BLOCK_Type type, | 287 | const void *data, enum GNUNET_BLOCK_Type type, |
288 | uint32_t priority, uint32_t anonymity, | 288 | uint32_t priority, uint32_t anonymity, |
289 | uint32_t replication, | 289 | uint32_t replication, |
290 | struct GNUNET_TIME_Absolute expiration, char **msg) | 290 | struct GNUNET_TIME_Absolute expiration, PluginPutCont cont, |
291 | void *cont_cls) | ||
291 | { | 292 | { |
292 | struct Plugin *plugin = cls; | 293 | struct Plugin *plugin = cls; |
293 | struct GNUNET_HashCode vhash; | 294 | struct GNUNET_HashCode vhash; |
@@ -326,12 +327,15 @@ postgres_plugin_put (void *cls, const struct GNUNET_HashCode * key, uint32_t siz | |||
326 | paramFormats, 1); | 327 | paramFormats, 1); |
327 | if (GNUNET_OK != | 328 | if (GNUNET_OK != |
328 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put")) | 329 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "put")) |
329 | return GNUNET_SYSERR; | 330 | { |
331 | cont (cont_cls, key, size, GNUNET_SYSERR, _("Postgress exec failure")); | ||
332 | return; | ||
333 | } | ||
330 | PQclear (ret); | 334 | PQclear (ret); |
331 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); | 335 | plugin->env->duc (plugin->env->cls, size + GNUNET_DATASTORE_ENTRY_OVERHEAD); |
332 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", | 336 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "datastore-postgres", |
333 | "Stored %u bytes in database\n", (unsigned int) size); | 337 | "Stored %u bytes in database\n", (unsigned int) size); |
334 | return GNUNET_OK; | 338 | cont (cont_cls, key, size, GNUNET_OK, NULL); |
335 | } | 339 | } |
336 | 340 | ||
337 | 341 | ||
@@ -753,12 +757,13 @@ postgres_plugin_get_expiration (void *cls, PluginDatumProcessor proc, | |||
753 | * @param expire new expiration time should be the | 757 | * @param expire new expiration time should be the |
754 | * MAX of any existing expiration time and | 758 | * MAX of any existing expiration time and |
755 | * this value | 759 | * this value |
756 | * @param msg set to error message | 760 | * @param cont continuation called with success or failure status |
757 | * @return GNUNET_OK on success | 761 | * @param cons_cls continuation closure |
758 | */ | 762 | */ |
759 | static int | 763 | static void |
760 | postgres_plugin_update (void *cls, uint64_t uid, int delta, | 764 | postgres_plugin_update (void *cls, uint64_t uid, int delta, |
761 | struct GNUNET_TIME_Absolute expire, char **msg) | 765 | struct GNUNET_TIME_Absolute expire, |
766 | PluginUpdateCont cont, void *cont_cls) | ||
762 | { | 767 | { |
763 | struct Plugin *plugin = cls; | 768 | struct Plugin *plugin = cls; |
764 | PGresult *ret; | 769 | PGresult *ret; |
@@ -783,9 +788,12 @@ postgres_plugin_update (void *cls, uint64_t uid, int delta, | |||
783 | paramFormats, 1); | 788 | paramFormats, 1); |
784 | if (GNUNET_OK != | 789 | if (GNUNET_OK != |
785 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update")) | 790 | GNUNET_POSTGRES_check_result (plugin->dbh, ret, PGRES_COMMAND_OK, "PQexecPrepared", "update")) |
786 | return GNUNET_SYSERR; | 791 | { |
792 | cont (cont_cls, GNUNET_SYSERR, NULL); | ||
793 | return; | ||
794 | } | ||
787 | PQclear (ret); | 795 | PQclear (ret); |
788 | return GNUNET_OK; | 796 | cont (cont_cls, GNUNET_OK, NULL); |
789 | } | 797 | } |
790 | 798 | ||
791 | 799 | ||
@@ -819,6 +827,7 @@ postgres_plugin_get_keys (void *cls, | |||
819 | } | 827 | } |
820 | } | 828 | } |
821 | PQclear (res); | 829 | PQclear (res); |
830 | proc (proc_cls, NULL, 0); | ||
822 | } | 831 | } |
823 | 832 | ||
824 | 833 | ||