From 819d4a33d766d1d585f73abb9d7c77d4f862970f Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Thu, 27 Dec 2007 23:17:24 +0000 Subject: allow hooks to pause RPC processing; this will allow hooks to do meaningful work before resuming the RPC processing; this is not backwards compatible. svn:r617 --- evrpc.h | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'evrpc.h') diff --git a/evrpc.h b/evrpc.h index 45f684ac..a1dd02aa 100644 --- a/evrpc.h +++ b/evrpc.h @@ -134,6 +134,11 @@ struct evrpc_req_generic { */ struct evhttp_request* http_req; + /* + * Temporary data store for marshaled data + */ + struct evbuffer* rpc_data; + /* * callback to reply and finish answering this rpc */ @@ -157,6 +162,7 @@ EVRPC_STRUCT(rpcname) { \ struct rplystruct* reply; \ struct evrpc* rpc; \ struct evhttp_request* http_req; \ + struct evbuffer* rpc_data; \ void (*done)(struct evrpc_status *, \ struct evrpc* rpc, void *request, void *reply); \ }; \ @@ -346,6 +352,9 @@ struct evrpc_request_wrapper { /* connection on which the request is being sent */ struct evhttp_connection *evcon; + /* the actual request */ + struct evhttp_request *req; + /* event for implementing request timeouts */ struct event ev_timeout; @@ -440,9 +449,22 @@ enum EVRPC_HOOK_TYPE { OUTPUT /**< apply the function to an output hook */ }; +/** + * Return value from hook processing functions + */ + +enum EVRPC_HOOK_RESULT { + EVRPC_TERMINATE = -1, /**< indicates the rpc should be terminated */ + EVRPC_CONTINUE = 0, /**< continue processing the rpc */ + EVRPC_PAUSE = 1, /**< pause processing request until resumed */ +}; + /** adds a processing hook to either an rpc base or rpc pool * - * If a hook returns -1, the processing is aborted. + * If a hook returns TERMINATE, the processing is aborted. On CONTINUE, + * the request is immediately processed after the hook returns. If the + * hook returns PAUSE, request processing stops until evrpc_resume_request() + * has been called. * * The add functions return handles that can be used for removing hooks. * @@ -455,7 +477,7 @@ enum EVRPC_HOOK_TYPE { */ void *evrpc_add_hook(void *vbase, enum EVRPC_HOOK_TYPE hook_type, - int (*cb)(struct evhttp_request *, struct evbuffer *, void *), + int (*cb)(void *, struct evhttp_request *, struct evbuffer *, void *), void *cb_arg); /** removes a previously added hook @@ -470,6 +492,14 @@ int evrpc_remove_hook(void *vbase, enum EVRPC_HOOK_TYPE hook_type, void *handle); +/** resume a paused request + * + * @param vbase a pointer to either struct evrpc_base or struct evrpc_pool + * @param ctx the context pointer provided to the original hook call + */ +int +evrpc_resume_request(void *vbase, void *ctx, enum EVRPC_HOOK_RESULT res); + #ifdef __cplusplus } #endif -- cgit v1.2.1