summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2013-10-10 23:22:25 +0000
committerroot <root@beaglebone.local.sublab.org>2013-10-10 23:22:25 +0000
commit77377be35acb8c9a7c437248c6ef9eb87f589004 (patch)
tree6572b0f3cd26fd0f9a5612f49eac6e607da09033
parentdbfd96c410369d6362d2eb3da52c4d58e959cfcc (diff)
async support (more or less)HEADmaster
-rw-r--r--jsonrpc.c9
-rw-r--r--jsonrpc.h3
2 files changed, 11 insertions, 1 deletions
diff --git a/jsonrpc.c b/jsonrpc.c
index a02bbaa..54ad96c 100644
--- a/jsonrpc.c
+++ b/jsonrpc.c
@@ -6,6 +6,9 @@
#include <jansson.h>
#include "jsonrpc.h"
+int dummy = 0;
+json_t *jsonrpc_async_dummy = (json_t *)&dummy;
+
json_t *jsonrpc_error_object(int code, json_t *data)
{
// reference to data is stolen
@@ -199,7 +202,11 @@ json_t *jsonrpc_handle_request_single(void *apparg, json_t *json_request, struct
json_result = NULL;
} else {
if (rc==0) {
- json_response = jsonrpc_result_response(json_id, json_result);
+ if (json_result == jsonrpc_async_dummy)
+ json_response = NULL;
+ else
+ json_response = jsonrpc_result_response(
+ json_id, json_result);
} else if (rc==JSONRPC_INVALID_PARAMS) {
json_response = jsonrpc_error_response(json_id,
jsonrpc_error_object(JSONRPC_INVALID_PARAMS, json_result));
diff --git a/jsonrpc.h b/jsonrpc.h
index d4a34f8..1a113ef 100644
--- a/jsonrpc.h
+++ b/jsonrpc.h
@@ -6,6 +6,8 @@
#define JSONRPC_INVALID_PARAMS -32602
#define JSONRPC_INTERNAL_ERROR -32603
+extern json_t *jsonrpc_async_dummy;
+
typedef int (*jsonrpc_method_prototype)(void *apparg, json_t *json_params, json_t **result);
struct jsonrpc_method_entry_t
{
@@ -15,4 +17,5 @@ struct jsonrpc_method_entry_t
};
char *jsonrpc_handler(void *apparg, const char *input, size_t input_len, struct jsonrpc_method_entry_t method_table[]);
+json_t *jsonrpc_result_response(json_t *json_id, json_t *json_result);
json_t *jsonrpc_error_object(int code, json_t *data);