diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/json_rpc.c | 8 | ||||
-rw-r--r-- | src/json_rpc.h | 2 | ||||
-rw-r--r-- | src/protocol.c | 2 |
3 files changed, 11 insertions, 1 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)) { diff --git a/src/json_rpc.h b/src/json_rpc.h index f3c67a9..090caca 100644 --- a/src/json_rpc.h +++ b/src/json_rpc.h @@ -16,6 +16,8 @@ struct jsonrpc_request; +int jsonrpc_generate_request_id(void); + int jsonrpc_request_create(struct jsonrpc_request **, int id, const char *method, struct json_object *params); void jsonrpc_request_destroy(struct jsonrpc_request *); diff --git a/src/protocol.c b/src/protocol.c index 977ed6e..8aac63d 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -25,7 +25,7 @@ int request_create_queue_run(struct jsonrpc_request **request, const struct run { int ret = 0; - ret = jsonrpc_request_create(request, 1, CMD_QUEUE_RUN, NULL); + ret = jsonrpc_request_create(request, jsonrpc_generate_request_id(), CMD_QUEUE_RUN, NULL); if (ret < 0) return ret; ret = jsonrpc_request_set_param_string(*request, run_key_url, run_get_url(run)); |