]> granicus.if.org Git - libevent/commitdiff
expose a way to create the rpc context manually
authorNiels Provos <provos@gmail.com>
Thu, 1 May 2008 02:08:26 +0000 (02:08 +0000)
committerNiels Provos <provos@gmail.com>
Thu, 1 May 2008 02:08:26 +0000 (02:08 +0000)
svn:r754

evrpc.c
evrpc.h
test/regress_rpc.c

diff --git a/evrpc.c b/evrpc.c
index 1d8bb604498f179a10fbc33a98c439a781be2d4d..191075d59fd95ab3a4919a1231a8128759a84302 100644 (file)
--- 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 f7f171349975b9cbaf44a926195d33e439ec08e2..b3f81769a1cd504156eb3169c6b102ac77990c24 100644 (file)
--- 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, \
index 3b40c372beafa0e8dedd72e36f19fb9b3b5d3622..bd8324b99c159ce64a5ec3a95da05a26fa0f738e 100644 (file)
@@ -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);