deimos.event2.rpc

@file rpc.h

This header files provides basic support for an RPC server and client.

To support RPCs in a server, every supported RPC command needs to be defined and registered.

EVRPC_HEADER(SendCommand, Request, Reply);

SendCommand is the name of the RPC command. Request is the name of a structure generated by event_rpcgen.py. It contains all parameters relating to the SendCommand RPC. The server needs to fill in the Reply structure. Reply is the name of a structure generated by event_rpcgen.py. It contains the answer to the RPC.

To register an RPC with an HTTP server, you need to first create an RPC base with:

evrpc_base* base = evrpc_init(http);

A specific RPC can then be registered with

EVRPC_REGISTER(base, SendCommand, Request, Reply, FunctionCB, arg);

when the server receives an appropriately formatted RPC, the user callback is invoked. The callback needs to fill in the reply structure.

void FunctionCB(EVRPC_STRUCT(SendCommand)* rpc, void* arg);

To send the reply, call EVRPC_REQUEST_DONE(rpc);

See the regression test for an example.

Members

Aliases

EVRPC_UNREGISTER
alias EVRPC_UNREGISTER = evrpc_unregister_rpc

Unregisters an already registered RPC

event_base
alias event_base = deimos.event2._opaque_structs.event_base
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evhttp_request
alias evhttp_request = deimos.event2._opaque_structs.evhttp_request
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc
alias evrpc = deimos.event2._opaque_structs.evrpc
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_hook_meta
alias evrpc_hook_meta = deimos.event2._opaque_structs.evrpc_hook_meta
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_req_generic
alias evrpc_req_generic = deimos.event2._opaque_structs.evrpc_req_generic
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_request_wrapper
alias evrpc_request_wrapper = deimos.event2._opaque_structs.evrpc_request_wrapper
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_status
alias evrpc_status = deimos.event2._opaque_structs.evrpc_status
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Enums

EVRPC_HOOK_RESULT
enum EVRPC_HOOK_RESULT

Return value from hook processing functions

EVRPC_HOOK_TYPE
enum EVRPC_HOOK_TYPE

Hooks for changing the input and output of RPCs; this can be used to implement compression, authentication, encryption, ...

Functions

EVRPC_MAKE_CTX
auto EVRPC_MAKE_CTX(evrpc_pool* pool, void* request, void* reply, U cb, V cbarg)

Creates a context structure that contains rpc specific information.

EVRPC_REQUEST_DONE
void EVRPC_REQUEST_DONE(rpc_req )

Creates the reply to an RPC request

EVRPC_REQUEST_HTTP
auto EVRPC_REQUEST_HTTP(T rpc_req)

Provides access to the HTTP request object underlying an RPC

EVTAG_ARRAY_ADD
auto EVTAG_ARRAY_ADD(T msg)

Allocates a new entry in the array and returns it.

EVTAG_ARRAY_ADD_VALUE
auto EVTAG_ARRAY_ADD_VALUE(T msg, U value)

Adds a value to an array.

EVTAG_ARRAY_ADD_VALUE
auto EVTAG_ARRAY_ADD_VALUE(T msg, U offset, V pvalue)

Gets a variable at the specified offset from the array.

EVTAG_ARRAY_LEN
auto EVTAG_ARRAY_LEN(T msg)

Returns the number of entries in the array.

EVTAG_ASSIGN
void EVTAG_ASSIGN(T msg, U value)

Assigns a value to the member in the message.

EVTAG_ASSIGN_WITH_LEN
void EVTAG_ASSIGN_WITH_LEN(T msg, U value, V len)

Assigns a value to the member in the message.

EVTAG_GET
auto EVTAG_GET(T msg, U pvalue)

Returns the value for a member.

EVTAG_GET
auto EVTAG_GET(T msg, U pvalue, V plen)

Returns the value for a member.

EVTAG_HAS
int EVTAG_HAS(T msg)

Determines if the member has been set in the message

evrpc_add_hook
void* evrpc_add_hook(void* vbase, EVRPC_HOOK_TYPE hook_type, ExternC!(int function(void*, evhttp_request*, evbuffer*, void*)) cb, void* cb_arg)

adds a processing hook to either an rpc base or rpc pool

evrpc_free
void evrpc_free(evrpc_base* base)

Frees the evrpc base

evrpc_get_reply
void* evrpc_get_reply(evrpc_req_generic* req)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_get_request
void* evrpc_get_request(evrpc_req_generic* req)

accessors for request and reply

evrpc_hook_add_meta
void evrpc_hook_add_meta(void* ctx, const(char)* key, const(void)* data, size_t data_size)

adds meta data to request

evrpc_hook_find_meta
int evrpc_hook_find_meta(void* ctx, const(char)* key, void** data, size_t* data_size)

retrieves meta data previously associated

evrpc_hook_get_connection
evhttp_connection* evrpc_hook_get_connection(void* ctx)

returns the connection object associated with the request

evrpc_init
evrpc_base* evrpc_init(evhttp* server)

Creates a new rpc base from which RPC requests can be received

evrpc_make_request
int evrpc_make_request(evrpc_request_wrapper* ctx)

Makes an RPC request based on the provided context.

evrpc_make_request_ctx
evrpc_request_wrapper* evrpc_make_request_ctx(evrpc_pool* pool, void* request, void* reply, const(char)* rpcname, ExternC!(void function(evbuffer*, void*)) req_marshal, ExternC!(void function(void*)) rpl_clear, ExternC!(int function(void*, evbuffer*)) rpl_unmarshal, ExternC!(void function(evrpc_status*, void*, void*, void*)) cb, void* cbarg)

use EVRPC_GENERATE instead

evrpc_pool_add_connection
void evrpc_pool_add_connection(evrpc_pool* pool, evhttp_connection* evcon)

Adds a connection over which rpc can be dispatched to the pool.

evrpc_pool_free
void evrpc_pool_free(evrpc_pool* pool)

frees an rpc connection pool

evrpc_pool_new
evrpc_pool* evrpc_pool_new(event_base* base)

creates an rpc connection pool

evrpc_pool_remove_connection
void evrpc_pool_remove_connection(evrpc_pool* pool, evhttp_connection* evcon)

Removes a connection from the pool.

evrpc_pool_set_timeout
void evrpc_pool_set_timeout(evrpc_pool* pool, int timeout_in_secs)

Sets the timeout in secs after which a request has to complete. The RPC is completely aborted if it does not complete by then. Setting the timeout to 0 means that it never timeouts and can be used to implement callback type RPCs.

evrpc_register_generic
int evrpc_register_generic(evrpc_base* base, const(char)* name, ExternC!(void function(evrpc_req_generic*, void*)) callback, void* cbarg, ExternC!(void* function(void*)) req_new, void* req_new_arg, ExternC!(void function(void*)) req_free, ExternC!(int function(void*, evbuffer*)) req_unmarshal, ExternC!(void* function(void*)) rpl_new, void* rpl_new_arg, ExternC!(void function(void*)) rpl_free, ExternC!(int function(void*)) rpl_complete, ExternC!(void function(evbuffer*, void*)) rpl_marshal)

Function for registering a generic RPC with the RPC base.

evrpc_register_rpc
int evrpc_register_rpc(evrpc_base* , evrpc* , ExternC!(void function(evrpc_req_generic*, void*)) , void* )

Low level function for registering an RPC with a server.

evrpc_remove_hook
int evrpc_remove_hook(void* vbase, EVRPC_HOOK_TYPE hook_type, void* handle)

removes a previously added hook

evrpc_request_done
void evrpc_request_done(evrpc_req_generic* req)

completes the server response to an rpc request

evrpc_request_get_pool
evrpc_pool* evrpc_request_get_pool(evrpc_request_wrapper* ctx)

accessors for obscure and undocumented functionality

evrpc_request_set_cb
void evrpc_request_set_cb(evrpc_request_wrapper* ctx, ExternC!(void function(evrpc_status*, void* request, void* reply, void* arg)) cb, void* cb_arg)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_request_set_pool
void evrpc_request_set_pool(evrpc_request_wrapper* ctx, evrpc_pool* pool)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_resume_request
int evrpc_resume_request(void* vbase, void* ctx, EVRPC_HOOK_RESULT res)

resume a paused request

evrpc_send_request_generic
int evrpc_send_request_generic(evrpc_pool* pool, void* request, void* reply, ExternC!(void function(evrpc_status*, void*, void*, void*)) cb, void* cb_arg, const(char)* rpcname, ExternC!(void function(evbuffer*, void*)) req_marshal, ExternC!(void function(void*)) rpl_clear, ExternC!(int function(void*, evbuffer*)) rpl_unmarshal)

Function for sending a generic RPC request.

evrpc_unregister_rpc
int evrpc_unregister_rpc(evrpc_base* base, const(char)* name)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Manifest constants

INPUT
enum INPUT;

Deprecated alias for EVRPC_INPUT. Not available on windows, where it * conflicts with platform headers.

OUTPUT
enum OUTPUT;

Deprecated alias for EVRPC_OUTPUT. Not available on windows, where it * conflicts with platform headers.

Mixin templates

EVRPC_GENERATE
mixintemplate EVRPC_GENERATE(string rpcname, string reqstruct, string rplystruct)

Generates the code for receiving and sending an RPC message

EVRPC_HEADER
mixintemplate EVRPC_HEADER(string rpcname, reqstruct, rplystruct)

Creates the definitions and prototypes for an RPC

Structs

evbuffer
struct evbuffer
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evhttp
struct evhttp
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evhttp_connection
struct evhttp_connection
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_base
struct evrpc_base
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
evrpc_pool
struct evrpc_pool
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Templates

ENRPC_MAKE_REQUEST
template ENRPC_MAKE_REQUEST(string name, string pool, string request, string reply, string cb, string cbarg)

launches an RPC and sends it to the server

EVRPC_REGISTER
template EVRPC_REGISTER(string base, string name, string request, string reply, string callback, string cbarg)

register RPCs with the HTTP Server

EVRPC_STRUCT
template EVRPC_STRUCT(string rpcname)

The type of a specific RPC Message

Meta