From df73d93b10e8e6014f61b1554be5b8553f34852a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 12 Nov 2023 01:10:07 +0100 Subject: json_rpc: add a routine to generate request IDs --- src/json_rpc.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/json_rpc.c') 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 +#include #include #include #include @@ -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)) { -- cgit v1.2.3