From e8f450f232cdb01349e5639181dd115ed5a663f0 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 1 May 2008 02:08:26 +0000 Subject: [PATCH] expose a way to create the rpc context manually svn:r754 --- evrpc.c | 2 +- evrpc.h | 28 ++++++++++++++++++++++++++-- test/regress_rpc.c | 22 ++++++++++++++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/evrpc.c b/evrpc.c index 1d8bb604..191075d5 100644 --- a/evrpc.c +++ b/evrpc.c @@ -784,7 +784,7 @@ evrpc_make_request(struct evrpc_request_wrapper *ctx) struct evrpc_request_wrapper * -evrpc_send_request_generic( +evrpc_make_request_ctx( struct evrpc_pool *pool, void *request, void *reply, const char *rpcname, void (*req_marshal)(struct evbuffer*, void *), diff --git a/evrpc.h b/evrpc.h index f7f17134..b3f81769 100644 --- a/evrpc.h +++ b/evrpc.h @@ -183,7 +183,7 @@ int evrpc_send_request_##rpcname(struct evrpc_pool *, \ struct evrpc_pool; /** use EVRPC_GENERATE instead */ -struct evrpc_request_wrapper *evrpc_send_request_generic( +struct evrpc_request_wrapper *evrpc_make_request_ctx( struct evrpc_pool *pool, void *request, void *reply, const char *rpcname, void (*req_marshal)(struct evbuffer*, void *), @@ -192,6 +192,30 @@ struct evrpc_request_wrapper *evrpc_send_request_generic( void (*cb)(struct evrpc_status *, void *, void *, void *), void *cbarg); +/** Creates a context structure that contains rpc specific information. + * + * EVRPC_MAKE_CTX is used to populate a RPC specific context that + * contains information about marshaling the RPC data types. + * + * @param rpcname the name of the RPC + * @param reqstruct the name of the RPC request structure + * @param replystruct the name of the RPC reply structure + * @param pool the evrpc_pool over which to make the request + * @param request a pointer to the RPC request structure object + * @param reply a pointer to the RPC reply structure object + * @param cb the callback function to call when the RPC has completed + * @param cbarg the argument to supply to the callback + */ +#define EVRPC_MAKE_CTX(rpcname, reqstruct, rplystruct, \ + pool, request, reply, cb, cbarg) \ + evrpc_make_request_ctx(pool, request, reply, \ + #rpcname, \ + (void (*)(struct evbuffer *, void *))reqstruct##_marshal, \ + (void (*)(void *))rplystruct##_clear, \ + (int (*)(void *, struct evbuffer *))rplystruct##_unmarshal, \ + (void (*)(struct evrpc_status *, void *, void *, void *))cb, \ + cbarg) + /** Generates the code for receiving and sending an RPC message * * EVRPC_GENERATE is used to create the code corresponding to sending @@ -210,7 +234,7 @@ int evrpc_send_request_##rpcname(struct evrpc_pool *pool, \ void *cbarg) { \ struct evrpc_status status; \ struct evrpc_request_wrapper *ctx; \ - ctx = evrpc_send_request_generic(pool, request, reply, \ + ctx = evrpc_make_request_ctx(pool, request, reply, \ #rpcname, \ (void (*)(struct evbuffer *, void *))reqstruct##_marshal, \ (void (*)(void *))rplystruct##_clear, \ diff --git a/test/regress_rpc.c b/test/regress_rpc.c index 3b40c372..bd8324b9 100644 --- a/test/regress_rpc.c +++ b/test/regress_rpc.c @@ -509,13 +509,31 @@ rpc_basic_client(void) event_dispatch(); - rpc_teardown(base); - if (test_ok != 2) { fprintf(stdout, "FAILED (2)\n"); exit(1); } + + /* we do it trice to make sure other stuff works, too */ + kill_clear(kill); + + { + struct evrpc_request_wrapper *ctx = + EVRPC_MAKE_CTX(Message, msg, kill, + pool, msg, kill, GotKillCb, NULL); + evrpc_make_request(ctx); + } + + event_dispatch(); + + rpc_teardown(base); + + if (test_ok != 3) { + fprintf(stdout, "FAILED (3)\n"); + exit(1); + } + fprintf(stdout, "OK\n"); msg_free(msg);