aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/json_rpc.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-11-12 01:10:07 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2023-11-12 01:10:07 +0100
commitdf73d93b10e8e6014f61b1554be5b8553f34852a (patch)
treec12c7742f366b4702ef707fc4eb1f5e5e66b0521 /src/json_rpc.c
parentrefactoring (diff)
downloadcimple-df73d93b10e8e6014f61b1554be5b8553f34852a.tar.gz
cimple-df73d93b10e8e6014f61b1554be5b8553f34852a.zip
json_rpc: add a routine to generate request IDs
Diffstat (limited to '')
-rw-r--r--src/json_rpc.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/json_rpc.c b/src/json_rpc.c
index 7630f64..31794ec 100644
--- a/src/json_rpc.c
+++ b/src/json_rpc.c
@@ -11,6 +11,7 @@
#include <json-c/json_object.h>
+#include <stdatomic.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@@ -52,6 +53,13 @@ static int jsonrpc_set_version(struct json_object *obj)
return json_set_string_const_key(obj, jsonrpc_key_version, jsonrpc_value_version);
}
+static _Atomic int jsonrpc_id_counter = 1;
+
+int jsonrpc_generate_request_id(void)
+{
+ return jsonrpc_id_counter++;
+}
+
static int jsonrpc_check_id_type(struct json_object *id)
{
if (!json_object_is_type(id, json_type_string) && !json_object_is_type(id, json_type_int)) {