Skip to content

Commit

Permalink
tools/cnode: show value ID when put completes
Browse files Browse the repository at this point in the history
  • Loading branch information
aberaud committed Feb 11, 2025
1 parent 5bf19c8 commit b9e00c7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tools/dhtcnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdatomic.h>
#include <inttypes.h>

#include <getopt.h>
#include <readline/readline.h>
Expand All @@ -38,6 +39,10 @@ struct listen_context {
dht_op_token* token;
size_t count;
};
struct put_context {
dht_runner* runner;
dht_value* value;
};

bool dht_value_callback(const dht_value* value, bool expired, void* user_data)
{
Expand Down Expand Up @@ -67,8 +72,10 @@ void dht_get_done_callback(bool ok, void* user_data)

void dht_put_done_callback(bool ok, void* user_data)
{
dht_runner* runner = (dht_runner*)user_data;
printf("Put completed: %s\n", ok ? "success !" : "failure :-(");
struct put_context* ctx = (struct put_context*)user_data;
printf("Put completed (id: %" PRIx64 "): %s\n", dht_value_get_id(ctx->value), ok ? "success !" : "failure :-(");
dht_value_unref(ctx->value);
free(ctx);
}

void dht_shutdown_callback(void* user_data)
Expand Down Expand Up @@ -261,8 +268,10 @@ int main(int argc, char **argv)
else if (!strcmp(cmd, "p")) {
key = parse_key(arg);
dht_value* val = dht_value_new_from_string(value);
dht_runner_put(runner, &key, val, dht_put_done_callback, runner, true);
dht_value_unref(val);
struct put_context* ctx = malloc(sizeof(struct put_context));
ctx->runner = runner;
ctx->value = val;
dht_runner_put(runner, &key, val, dht_put_done_callback, ctx, true);
}
else {
printf("Unknown command: %s\n", cmd);
Expand Down

0 comments on commit b9e00c7

Please sign in to comment.