diff --git a/demo/demo-async-client.c b/demo/demo-async-client.c index 12250eb..30d227d 100644 --- a/demo/demo-async-client.c +++ b/demo/demo-async-client.c @@ -28,7 +28,7 @@ typedef struct { /* rpc_priv is used by the rpc_client to store information related to * this rpc call. */ -static int transport_send(void *arg, const char *fcall_str, +static int transport_send(void *arg, char *fcall_str, size_t fcall_len, void *rpc_priv) { TcpTransport *trans = arg; @@ -49,6 +49,7 @@ static int transport_send(void *arg, const char *fcall_str, } trans->rpc_priv = rpc_priv; + g_free (fcall_str); return 0; } diff --git a/lib/gencode.py b/lib/gencode.py index 5dc5811..afe75c6 100644 --- a/lib/gencode.py +++ b/lib/gencode.py @@ -333,7 +333,7 @@ def gen_dfun_macro_list(): async_dfun_template = r""" #define SEARPC_CLIENT_ASYNC_DEFUN_${RET_TYPE}__${ARG_TYPES}(funcname, gtype) \ int \ -funcname (SearpcClient *client, ${args}, \ +funcname (SearpcClient *client, ${args} \ AsyncCallback callback, void *user_data) \ { \ char *fcall; \ @@ -358,7 +358,7 @@ def gen_async_dfun_macro(ret_type, arg_types): args = "" for i, arg_type in enumerate(arg_types): - args += type_table[arg_type][0] + " param" + str(i+1) + args += type_table[arg_type][0] + " param" + str(i+1) + ", " fcall_args = "" for i, arg_type in enumerate(arg_types): diff --git a/lib/searpc-client.c b/lib/searpc-client.c index 9123c59..cc0a682 100644 --- a/lib/searpc-client.c +++ b/lib/searpc-client.c @@ -74,7 +74,7 @@ searpc_client_generic_callback (char *retstr, size_t len, int searpc_client_async_call (SearpcClient *client, - const gchar *fcall_str, + gchar *fcall_str, size_t fcall_len, AsyncCallback callback, const gchar *ret_type, diff --git a/lib/searpc-client.h b/lib/searpc-client.h index 8be753d..8bd843e 100644 --- a/lib/searpc-client.h +++ b/lib/searpc-client.h @@ -7,9 +7,13 @@ typedef char *(*TransportCB)(void *arg, const gchar *fcall_str, size_t fcall_len, size_t *ret_len); -/* rpc_priv is used by the rpc_client to store information related to - * this rpc call. */ -typedef int (*AsyncTransportSend)(void *arg, const gchar *fcall_str, +/** + * @rpc_priv is used by the rpc_client to store information related to + * this rpc call. + * @fcall_str is an allocated string, and the sender should free it + * when not needed. + */ +typedef int (*AsyncTransportSend)(void *arg, gchar *fcall_str, size_t fcall_len, void *rpc_priv); typedef void (*AsyncCallback) (void *result, void *user_data, GError *error); @@ -42,13 +46,15 @@ char* searpc_client_transport_send (SearpcClient *client, * @cbdata: the data that will be given to the callback. */ int searpc_client_async_call (SearpcClient *client, - const gchar *fcall_str, + gchar *fcall_str, size_t fcall_len, AsyncCallback callback, const gchar *ret_type, int gtype, void *cbdata); +/* called by the transport layer, the rpc layer should be able to + * modify the str, but not take ownership of it */ int searpc_client_generic_callback (char *retstr, size_t len, void *vdata, const char *errstr);