Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/include/event2
File: rpc.h
/*
[0] Fix | Delete
* Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
[1] Fix | Delete
* Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
[2] Fix | Delete
*
[3] Fix | Delete
* Redistribution and use in source and binary forms, with or without
[4] Fix | Delete
* modification, are permitted provided that the following conditions
[5] Fix | Delete
* are met:
[6] Fix | Delete
* 1. Redistributions of source code must retain the above copyright
[7] Fix | Delete
* notice, this list of conditions and the following disclaimer.
[8] Fix | Delete
* 2. Redistributions in binary form must reproduce the above copyright
[9] Fix | Delete
* notice, this list of conditions and the following disclaimer in the
[10] Fix | Delete
* documentation and/or other materials provided with the distribution.
[11] Fix | Delete
* 3. The name of the author may not be used to endorse or promote products
[12] Fix | Delete
* derived from this software without specific prior written permission.
[13] Fix | Delete
*
[14] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
[15] Fix | Delete
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
[16] Fix | Delete
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
[17] Fix | Delete
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
[18] Fix | Delete
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
[19] Fix | Delete
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
[20] Fix | Delete
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[21] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
[22] Fix | Delete
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
[23] Fix | Delete
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[24] Fix | Delete
*/
[25] Fix | Delete
#ifndef EVENT2_RPC_H_INCLUDED_
[26] Fix | Delete
#define EVENT2_RPC_H_INCLUDED_
[27] Fix | Delete
[28] Fix | Delete
#ifdef __cplusplus
[29] Fix | Delete
extern "C" {
[30] Fix | Delete
#endif
[31] Fix | Delete
[32] Fix | Delete
/** @file rpc.h
[33] Fix | Delete
*
[34] Fix | Delete
* This header files provides basic support for an RPC server and client.
[35] Fix | Delete
*
[36] Fix | Delete
* To support RPCs in a server, every supported RPC command needs to be
[37] Fix | Delete
* defined and registered.
[38] Fix | Delete
*
[39] Fix | Delete
* EVRPC_HEADER(SendCommand, Request, Reply);
[40] Fix | Delete
*
[41] Fix | Delete
* SendCommand is the name of the RPC command.
[42] Fix | Delete
* Request is the name of a structure generated by event_rpcgen.py.
[43] Fix | Delete
* It contains all parameters relating to the SendCommand RPC. The
[44] Fix | Delete
* server needs to fill in the Reply structure.
[45] Fix | Delete
* Reply is the name of a structure generated by event_rpcgen.py. It
[46] Fix | Delete
* contains the answer to the RPC.
[47] Fix | Delete
*
[48] Fix | Delete
* To register an RPC with an HTTP server, you need to first create an RPC
[49] Fix | Delete
* base with:
[50] Fix | Delete
*
[51] Fix | Delete
* struct evrpc_base *base = evrpc_init(http);
[52] Fix | Delete
*
[53] Fix | Delete
* A specific RPC can then be registered with
[54] Fix | Delete
*
[55] Fix | Delete
* EVRPC_REGISTER(base, SendCommand, Request, Reply, FunctionCB, arg);
[56] Fix | Delete
*
[57] Fix | Delete
* when the server receives an appropriately formatted RPC, the user callback
[58] Fix | Delete
* is invoked. The callback needs to fill in the reply structure.
[59] Fix | Delete
*
[60] Fix | Delete
* void FunctionCB(EVRPC_STRUCT(SendCommand)* rpc, void *arg);
[61] Fix | Delete
*
[62] Fix | Delete
* To send the reply, call EVRPC_REQUEST_DONE(rpc);
[63] Fix | Delete
*
[64] Fix | Delete
* See the regression test for an example.
[65] Fix | Delete
*/
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
Determines if the member has been set in the message
[69] Fix | Delete
[70] Fix | Delete
@param msg the message to inspect
[71] Fix | Delete
@param member the member variable to test for presences
[72] Fix | Delete
@return 1 if it's present or 0 otherwise.
[73] Fix | Delete
*/
[74] Fix | Delete
#define EVTAG_HAS(msg, member) \
[75] Fix | Delete
((msg)->member##_set == 1)
[76] Fix | Delete
[77] Fix | Delete
#ifndef EVENT2_RPC_COMPAT_H_INCLUDED_
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
Assigns a value to the member in the message.
[81] Fix | Delete
[82] Fix | Delete
@param msg the message to which to assign a value
[83] Fix | Delete
@param member the name of the member variable
[84] Fix | Delete
@param value the value to assign
[85] Fix | Delete
*/
[86] Fix | Delete
#define EVTAG_ASSIGN(msg, member, value) \
[87] Fix | Delete
(*(msg)->base->member##_assign)((msg), (value))
[88] Fix | Delete
/**
[89] Fix | Delete
Assigns a value to the member in the message.
[90] Fix | Delete
[91] Fix | Delete
@param msg the message to which to assign a value
[92] Fix | Delete
@param member the name of the member variable
[93] Fix | Delete
@param value the value to assign
[94] Fix | Delete
@param len the length of the value
[95] Fix | Delete
*/
[96] Fix | Delete
#define EVTAG_ASSIGN_WITH_LEN(msg, member, value, len) \
[97] Fix | Delete
(*(msg)->base->member##_assign)((msg), (value), (len))
[98] Fix | Delete
/**
[99] Fix | Delete
Returns the value for a member.
[100] Fix | Delete
[101] Fix | Delete
@param msg the message from which to get the value
[102] Fix | Delete
@param member the name of the member variable
[103] Fix | Delete
@param pvalue a pointer to the variable to hold the value
[104] Fix | Delete
@return 0 on success, -1 otherwise.
[105] Fix | Delete
*/
[106] Fix | Delete
#define EVTAG_GET(msg, member, pvalue) \
[107] Fix | Delete
(*(msg)->base->member##_get)((msg), (pvalue))
[108] Fix | Delete
/**
[109] Fix | Delete
Returns the value for a member.
[110] Fix | Delete
[111] Fix | Delete
@param msg the message from which to get the value
[112] Fix | Delete
@param member the name of the member variable
[113] Fix | Delete
@param pvalue a pointer to the variable to hold the value
[114] Fix | Delete
@param plen a pointer to the length of the value
[115] Fix | Delete
@return 0 on success, -1 otherwise.
[116] Fix | Delete
*/
[117] Fix | Delete
#define EVTAG_GET_WITH_LEN(msg, member, pvalue, plen) \
[118] Fix | Delete
(*(msg)->base->member##_get)((msg), (pvalue), (plen))
[119] Fix | Delete
[120] Fix | Delete
#endif /* EVENT2_RPC_COMPAT_H_INCLUDED_ */
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
Adds a value to an array.
[124] Fix | Delete
*/
[125] Fix | Delete
#define EVTAG_ARRAY_ADD_VALUE(msg, member, value) \
[126] Fix | Delete
(*(msg)->base->member##_add)((msg), (value))
[127] Fix | Delete
/**
[128] Fix | Delete
Allocates a new entry in the array and returns it.
[129] Fix | Delete
*/
[130] Fix | Delete
#define EVTAG_ARRAY_ADD(msg, member) \
[131] Fix | Delete
(*(msg)->base->member##_add)(msg)
[132] Fix | Delete
/**
[133] Fix | Delete
Gets a variable at the specified offset from the array.
[134] Fix | Delete
*/
[135] Fix | Delete
#define EVTAG_ARRAY_GET(msg, member, offset, pvalue) \
[136] Fix | Delete
(*(msg)->base->member##_get)((msg), (offset), (pvalue))
[137] Fix | Delete
/**
[138] Fix | Delete
Returns the number of entries in the array.
[139] Fix | Delete
*/
[140] Fix | Delete
#define EVTAG_ARRAY_LEN(msg, member) ((msg)->member##_length)
[141] Fix | Delete
[142] Fix | Delete
[143] Fix | Delete
struct evbuffer;
[144] Fix | Delete
struct event_base;
[145] Fix | Delete
struct evrpc_req_generic;
[146] Fix | Delete
struct evrpc_request_wrapper;
[147] Fix | Delete
struct evrpc;
[148] Fix | Delete
[149] Fix | Delete
/** The type of a specific RPC Message
[150] Fix | Delete
*
[151] Fix | Delete
* @param rpcname the name of the RPC message
[152] Fix | Delete
*/
[153] Fix | Delete
#define EVRPC_STRUCT(rpcname) struct evrpc_req__##rpcname
[154] Fix | Delete
[155] Fix | Delete
struct evhttp_request;
[156] Fix | Delete
struct evrpc_status;
[157] Fix | Delete
struct evrpc_hook_meta;
[158] Fix | Delete
[159] Fix | Delete
/** Creates the definitions and prototypes for an RPC
[160] Fix | Delete
*
[161] Fix | Delete
* You need to use EVRPC_HEADER to create structures and function prototypes
[162] Fix | Delete
* needed by the server and client implementation. The structures have to be
[163] Fix | Delete
* defined in an .rpc file and converted to source code via event_rpcgen.py
[164] Fix | Delete
*
[165] Fix | Delete
* @param rpcname the name of the RPC
[166] Fix | Delete
* @param reqstruct the name of the RPC request structure
[167] Fix | Delete
* @param replystruct the name of the RPC reply structure
[168] Fix | Delete
* @see EVRPC_GENERATE()
[169] Fix | Delete
*/
[170] Fix | Delete
#define EVRPC_HEADER(rpcname, reqstruct, rplystruct) \
[171] Fix | Delete
EVRPC_STRUCT(rpcname) { \
[172] Fix | Delete
struct evrpc_hook_meta *hook_meta; \
[173] Fix | Delete
struct reqstruct* request; \
[174] Fix | Delete
struct rplystruct* reply; \
[175] Fix | Delete
struct evrpc* rpc; \
[176] Fix | Delete
struct evhttp_request* http_req; \
[177] Fix | Delete
struct evbuffer* rpc_data; \
[178] Fix | Delete
}; \
[179] Fix | Delete
int evrpc_send_request_##rpcname(struct evrpc_pool *, \
[180] Fix | Delete
struct reqstruct *, struct rplystruct *, \
[181] Fix | Delete
void (*)(struct evrpc_status *, \
[182] Fix | Delete
struct reqstruct *, struct rplystruct *, void *cbarg), \
[183] Fix | Delete
void *);
[184] Fix | Delete
[185] Fix | Delete
struct evrpc_pool;
[186] Fix | Delete
[187] Fix | Delete
/** use EVRPC_GENERATE instead */
[188] Fix | Delete
struct evrpc_request_wrapper *evrpc_make_request_ctx(
[189] Fix | Delete
struct evrpc_pool *pool, void *request, void *reply,
[190] Fix | Delete
const char *rpcname,
[191] Fix | Delete
void (*req_marshal)(struct evbuffer*, void *),
[192] Fix | Delete
void (*rpl_clear)(void *),
[193] Fix | Delete
int (*rpl_unmarshal)(void *, struct evbuffer *),
[194] Fix | Delete
void (*cb)(struct evrpc_status *, void *, void *, void *),
[195] Fix | Delete
void *cbarg);
[196] Fix | Delete
[197] Fix | Delete
/** Creates a context structure that contains rpc specific information.
[198] Fix | Delete
*
[199] Fix | Delete
* EVRPC_MAKE_CTX is used to populate a RPC specific context that
[200] Fix | Delete
* contains information about marshaling the RPC data types.
[201] Fix | Delete
*
[202] Fix | Delete
* @param rpcname the name of the RPC
[203] Fix | Delete
* @param reqstruct the name of the RPC request structure
[204] Fix | Delete
* @param replystruct the name of the RPC reply structure
[205] Fix | Delete
* @param pool the evrpc_pool over which to make the request
[206] Fix | Delete
* @param request a pointer to the RPC request structure object
[207] Fix | Delete
* @param reply a pointer to the RPC reply structure object
[208] Fix | Delete
* @param cb the callback function to call when the RPC has completed
[209] Fix | Delete
* @param cbarg the argument to supply to the callback
[210] Fix | Delete
*/
[211] Fix | Delete
#define EVRPC_MAKE_CTX(rpcname, reqstruct, rplystruct, \
[212] Fix | Delete
pool, request, reply, cb, cbarg) \
[213] Fix | Delete
evrpc_make_request_ctx(pool, request, reply, \
[214] Fix | Delete
#rpcname, \
[215] Fix | Delete
(void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
[216] Fix | Delete
(void (*)(void *))rplystruct##_clear, \
[217] Fix | Delete
(int (*)(void *, struct evbuffer *))rplystruct##_unmarshal, \
[218] Fix | Delete
(void (*)(struct evrpc_status *, void *, void *, void *))cb, \
[219] Fix | Delete
cbarg)
[220] Fix | Delete
[221] Fix | Delete
/** Generates the code for receiving and sending an RPC message
[222] Fix | Delete
*
[223] Fix | Delete
* EVRPC_GENERATE is used to create the code corresponding to sending
[224] Fix | Delete
* and receiving a particular RPC message
[225] Fix | Delete
*
[226] Fix | Delete
* @param rpcname the name of the RPC
[227] Fix | Delete
* @param reqstruct the name of the RPC request structure
[228] Fix | Delete
* @param replystruct the name of the RPC reply structure
[229] Fix | Delete
* @see EVRPC_HEADER()
[230] Fix | Delete
*/
[231] Fix | Delete
#define EVRPC_GENERATE(rpcname, reqstruct, rplystruct) \
[232] Fix | Delete
int evrpc_send_request_##rpcname(struct evrpc_pool *pool, \
[233] Fix | Delete
struct reqstruct *request, struct rplystruct *reply, \
[234] Fix | Delete
void (*cb)(struct evrpc_status *, \
[235] Fix | Delete
struct reqstruct *, struct rplystruct *, void *cbarg), \
[236] Fix | Delete
void *cbarg) { \
[237] Fix | Delete
return evrpc_send_request_generic(pool, request, reply, \
[238] Fix | Delete
(void (*)(struct evrpc_status *, void *, void *, void *))cb, \
[239] Fix | Delete
cbarg, \
[240] Fix | Delete
#rpcname, \
[241] Fix | Delete
(void (*)(struct evbuffer *, void *))reqstruct##_marshal, \
[242] Fix | Delete
(void (*)(void *))rplystruct##_clear, \
[243] Fix | Delete
(int (*)(void *, struct evbuffer *))rplystruct##_unmarshal); \
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/** Provides access to the HTTP request object underlying an RPC
[247] Fix | Delete
*
[248] Fix | Delete
* Access to the underlying http object; can be used to look at headers or
[249] Fix | Delete
* for getting the remote ip address
[250] Fix | Delete
*
[251] Fix | Delete
* @param rpc_req the rpc request structure provided to the server callback
[252] Fix | Delete
* @return an struct evhttp_request object that can be inspected for
[253] Fix | Delete
* HTTP headers or sender information.
[254] Fix | Delete
*/
[255] Fix | Delete
#define EVRPC_REQUEST_HTTP(rpc_req) (rpc_req)->http_req
[256] Fix | Delete
[257] Fix | Delete
/** completes the server response to an rpc request */
[258] Fix | Delete
void evrpc_request_done(struct evrpc_req_generic *req);
[259] Fix | Delete
[260] Fix | Delete
/** accessors for request and reply */
[261] Fix | Delete
void *evrpc_get_request(struct evrpc_req_generic *req);
[262] Fix | Delete
void *evrpc_get_reply(struct evrpc_req_generic *req);
[263] Fix | Delete
[264] Fix | Delete
/** Creates the reply to an RPC request
[265] Fix | Delete
*
[266] Fix | Delete
* EVRPC_REQUEST_DONE is used to answer a request; the reply is expected
[267] Fix | Delete
* to have been filled in. The request and reply pointers become invalid
[268] Fix | Delete
* after this call has finished.
[269] Fix | Delete
*
[270] Fix | Delete
* @param rpc_req the rpc request structure provided to the server callback
[271] Fix | Delete
*/
[272] Fix | Delete
#define EVRPC_REQUEST_DONE(rpc_req) do { \
[273] Fix | Delete
struct evrpc_req_generic *req_ = (struct evrpc_req_generic *)(rpc_req); \
[274] Fix | Delete
evrpc_request_done(req_); \
[275] Fix | Delete
} while (0)
[276] Fix | Delete
[277] Fix | Delete
[278] Fix | Delete
struct evrpc_base;
[279] Fix | Delete
struct evhttp;
[280] Fix | Delete
[281] Fix | Delete
/* functions to start up the rpc system */
[282] Fix | Delete
[283] Fix | Delete
/** Creates a new rpc base from which RPC requests can be received
[284] Fix | Delete
*
[285] Fix | Delete
* @param server a pointer to an existing HTTP server
[286] Fix | Delete
* @return a newly allocated evrpc_base struct
[287] Fix | Delete
* @see evrpc_free()
[288] Fix | Delete
*/
[289] Fix | Delete
struct evrpc_base *evrpc_init(struct evhttp *server);
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Frees the evrpc base
[293] Fix | Delete
*
[294] Fix | Delete
* For now, you are responsible for making sure that no rpcs are ongoing.
[295] Fix | Delete
*
[296] Fix | Delete
* @param base the evrpc_base object to be freed
[297] Fix | Delete
* @see evrpc_init
[298] Fix | Delete
*/
[299] Fix | Delete
void evrpc_free(struct evrpc_base *base);
[300] Fix | Delete
[301] Fix | Delete
/** register RPCs with the HTTP Server
[302] Fix | Delete
*
[303] Fix | Delete
* registers a new RPC with the HTTP server, each RPC needs to have
[304] Fix | Delete
* a unique name under which it can be identified.
[305] Fix | Delete
*
[306] Fix | Delete
* @param base the evrpc_base structure in which the RPC should be
[307] Fix | Delete
* registered.
[308] Fix | Delete
* @param name the name of the RPC
[309] Fix | Delete
* @param request the name of the RPC request structure
[310] Fix | Delete
* @param reply the name of the RPC reply structure
[311] Fix | Delete
* @param callback the callback that should be invoked when the RPC
[312] Fix | Delete
* is received. The callback has the following prototype
[313] Fix | Delete
* void (*callback)(EVRPC_STRUCT(Message)* rpc, void *arg)
[314] Fix | Delete
* @param cbarg an additional parameter that can be passed to the callback.
[315] Fix | Delete
* The parameter can be used to carry around state.
[316] Fix | Delete
*/
[317] Fix | Delete
#define EVRPC_REGISTER(base, name, request, reply, callback, cbarg) \
[318] Fix | Delete
evrpc_register_generic(base, #name, \
[319] Fix | Delete
(void (*)(struct evrpc_req_generic *, void *))callback, cbarg, \
[320] Fix | Delete
(void *(*)(void *))request##_new, NULL, \
[321] Fix | Delete
(void (*)(void *))request##_free, \
[322] Fix | Delete
(int (*)(void *, struct evbuffer *))request##_unmarshal, \
[323] Fix | Delete
(void *(*)(void *))reply##_new, NULL, \
[324] Fix | Delete
(void (*)(void *))reply##_free, \
[325] Fix | Delete
(int (*)(void *))reply##_complete, \
[326] Fix | Delete
(void (*)(struct evbuffer *, void *))reply##_marshal)
[327] Fix | Delete
[328] Fix | Delete
/**
[329] Fix | Delete
Low level function for registering an RPC with a server.
[330] Fix | Delete
[331] Fix | Delete
Use EVRPC_REGISTER() instead.
[332] Fix | Delete
[333] Fix | Delete
@see EVRPC_REGISTER()
[334] Fix | Delete
*/
[335] Fix | Delete
int evrpc_register_rpc(struct evrpc_base *, struct evrpc *,
[336] Fix | Delete
void (*)(struct evrpc_req_generic*, void *), void *);
[337] Fix | Delete
[338] Fix | Delete
/**
[339] Fix | Delete
* Unregisters an already registered RPC
[340] Fix | Delete
*
[341] Fix | Delete
* @param base the evrpc_base object from which to unregister an RPC
[342] Fix | Delete
* @param name the name of the rpc to unregister
[343] Fix | Delete
* @return -1 on error or 0 when successful.
[344] Fix | Delete
* @see EVRPC_REGISTER()
[345] Fix | Delete
*/
[346] Fix | Delete
#define EVRPC_UNREGISTER(base, name) evrpc_unregister_rpc((base), #name)
[347] Fix | Delete
[348] Fix | Delete
int evrpc_unregister_rpc(struct evrpc_base *base, const char *name);
[349] Fix | Delete
[350] Fix | Delete
/*
[351] Fix | Delete
* Client-side RPC support
[352] Fix | Delete
*/
[353] Fix | Delete
[354] Fix | Delete
struct evhttp_connection;
[355] Fix | Delete
struct evrpc_status;
[356] Fix | Delete
[357] Fix | Delete
/** launches an RPC and sends it to the server
[358] Fix | Delete
*
[359] Fix | Delete
* EVRPC_MAKE_REQUEST() is used by the client to send an RPC to the server.
[360] Fix | Delete
*
[361] Fix | Delete
* @param name the name of the RPC
[362] Fix | Delete
* @param pool the evrpc_pool that contains the connection objects over which
[363] Fix | Delete
* the request should be sent.
[364] Fix | Delete
* @param request a pointer to the RPC request structure - it contains the
[365] Fix | Delete
* data to be sent to the server.
[366] Fix | Delete
* @param reply a pointer to the RPC reply structure. It is going to be filled
[367] Fix | Delete
* if the request was answered successfully
[368] Fix | Delete
* @param cb the callback to invoke when the RPC request has been answered
[369] Fix | Delete
* @param cbarg an additional argument to be passed to the client
[370] Fix | Delete
* @return 0 on success, -1 on failure
[371] Fix | Delete
*/
[372] Fix | Delete
#define EVRPC_MAKE_REQUEST(name, pool, request, reply, cb, cbarg) \
[373] Fix | Delete
evrpc_send_request_##name((pool), (request), (reply), (cb), (cbarg))
[374] Fix | Delete
[375] Fix | Delete
/**
[376] Fix | Delete
Makes an RPC request based on the provided context.
[377] Fix | Delete
[378] Fix | Delete
This is a low-level function and should not be used directly
[379] Fix | Delete
unless a custom context object is provided. Use EVRPC_MAKE_REQUEST()
[380] Fix | Delete
instead.
[381] Fix | Delete
[382] Fix | Delete
@param ctx a context from EVRPC_MAKE_CTX()
[383] Fix | Delete
@returns 0 on success, -1 otherwise.
[384] Fix | Delete
@see EVRPC_MAKE_REQUEST(), EVRPC_MAKE_CTX()
[385] Fix | Delete
*/
[386] Fix | Delete
int evrpc_make_request(struct evrpc_request_wrapper *ctx);
[387] Fix | Delete
[388] Fix | Delete
/** creates an rpc connection pool
[389] Fix | Delete
*
[390] Fix | Delete
* a pool has a number of connections associated with it.
[391] Fix | Delete
* rpc requests are always made via a pool.
[392] Fix | Delete
*
[393] Fix | Delete
* @param base a pointer to an struct event_based object; can be left NULL
[394] Fix | Delete
* in singled-threaded applications
[395] Fix | Delete
* @return a newly allocated struct evrpc_pool object
[396] Fix | Delete
* @see evrpc_pool_free()
[397] Fix | Delete
*/
[398] Fix | Delete
struct evrpc_pool *evrpc_pool_new(struct event_base *base);
[399] Fix | Delete
/** frees an rpc connection pool
[400] Fix | Delete
*
[401] Fix | Delete
* @param pool a pointer to an evrpc_pool allocated via evrpc_pool_new()
[402] Fix | Delete
* @see evrpc_pool_new()
[403] Fix | Delete
*/
[404] Fix | Delete
void evrpc_pool_free(struct evrpc_pool *pool);
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* Adds a connection over which rpc can be dispatched to the pool.
[408] Fix | Delete
*
[409] Fix | Delete
* The connection object must have been newly created.
[410] Fix | Delete
*
[411] Fix | Delete
* @param pool the pool to which to add the connection
[412] Fix | Delete
* @param evcon the connection to add to the pool.
[413] Fix | Delete
*/
[414] Fix | Delete
void evrpc_pool_add_connection(struct evrpc_pool *pool,
[415] Fix | Delete
struct evhttp_connection *evcon);
[416] Fix | Delete
[417] Fix | Delete
/**
[418] Fix | Delete
* Removes a connection from the pool.
[419] Fix | Delete
*
[420] Fix | Delete
* The connection object must have been newly created.
[421] Fix | Delete
*
[422] Fix | Delete
* @param pool the pool from which to remove the connection
[423] Fix | Delete
* @param evcon the connection to remove from the pool.
[424] Fix | Delete
*/
[425] Fix | Delete
void evrpc_pool_remove_connection(struct evrpc_pool *pool,
[426] Fix | Delete
struct evhttp_connection *evcon);
[427] Fix | Delete
[428] Fix | Delete
/**
[429] Fix | Delete
* Sets the timeout in secs after which a request has to complete. The
[430] Fix | Delete
* RPC is completely aborted if it does not complete by then. Setting
[431] Fix | Delete
* the timeout to 0 means that it never timeouts and can be used to
[432] Fix | Delete
* implement callback type RPCs.
[433] Fix | Delete
*
[434] Fix | Delete
* Any connection already in the pool will be updated with the new
[435] Fix | Delete
* timeout. Connections added to the pool after set_timeout has be
[436] Fix | Delete
* called receive the pool timeout only if no timeout has been set
[437] Fix | Delete
* for the connection itself.
[438] Fix | Delete
*
[439] Fix | Delete
* @param pool a pointer to a struct evrpc_pool object
[440] Fix | Delete
* @param timeout_in_secs the number of seconds after which a request should
[441] Fix | Delete
* timeout and a failure be returned to the callback.
[442] Fix | Delete
*/
[443] Fix | Delete
void evrpc_pool_set_timeout(struct evrpc_pool *pool, int timeout_in_secs);
[444] Fix | Delete
[445] Fix | Delete
/**
[446] Fix | Delete
* Hooks for changing the input and output of RPCs; this can be used to
[447] Fix | Delete
* implement compression, authentication, encryption, ...
[448] Fix | Delete
*/
[449] Fix | Delete
[450] Fix | Delete
enum EVRPC_HOOK_TYPE {
[451] Fix | Delete
EVRPC_INPUT, /**< apply the function to an input hook */
[452] Fix | Delete
EVRPC_OUTPUT /**< apply the function to an output hook */
[453] Fix | Delete
};
[454] Fix | Delete
[455] Fix | Delete
#ifndef _WIN32
[456] Fix | Delete
/** Deprecated alias for EVRPC_INPUT. Not available on windows, where it
[457] Fix | Delete
* conflicts with platform headers. */
[458] Fix | Delete
#define INPUT EVRPC_INPUT
[459] Fix | Delete
/** Deprecated alias for EVRPC_OUTPUT. Not available on windows, where it
[460] Fix | Delete
* conflicts with platform headers. */
[461] Fix | Delete
#define OUTPUT EVRPC_OUTPUT
[462] Fix | Delete
#endif
[463] Fix | Delete
[464] Fix | Delete
/**
[465] Fix | Delete
* Return value from hook processing functions
[466] Fix | Delete
*/
[467] Fix | Delete
[468] Fix | Delete
enum EVRPC_HOOK_RESULT {
[469] Fix | Delete
EVRPC_TERMINATE = -1, /**< indicates the rpc should be terminated */
[470] Fix | Delete
EVRPC_CONTINUE = 0, /**< continue processing the rpc */
[471] Fix | Delete
EVRPC_PAUSE = 1 /**< pause processing request until resumed */
[472] Fix | Delete
};
[473] Fix | Delete
[474] Fix | Delete
/** adds a processing hook to either an rpc base or rpc pool
[475] Fix | Delete
*
[476] Fix | Delete
* If a hook returns TERMINATE, the processing is aborted. On CONTINUE,
[477] Fix | Delete
* the request is immediately processed after the hook returns. If the
[478] Fix | Delete
* hook returns PAUSE, request processing stops until evrpc_resume_request()
[479] Fix | Delete
* has been called.
[480] Fix | Delete
*
[481] Fix | Delete
* The add functions return handles that can be used for removing hooks.
[482] Fix | Delete
*
[483] Fix | Delete
* @param vbase a pointer to either struct evrpc_base or struct evrpc_pool
[484] Fix | Delete
* @param hook_type either INPUT or OUTPUT
[485] Fix | Delete
* @param cb the callback to call when the hook is activated
[486] Fix | Delete
* @param cb_arg an additional argument for the callback
[487] Fix | Delete
* @return a handle to the hook so it can be removed later
[488] Fix | Delete
* @see evrpc_remove_hook()
[489] Fix | Delete
*/
[490] Fix | Delete
void *evrpc_add_hook(void *vbase,
[491] Fix | Delete
enum EVRPC_HOOK_TYPE hook_type,
[492] Fix | Delete
int (*cb)(void *, struct evhttp_request *, struct evbuffer *, void *),
[493] Fix | Delete
void *cb_arg);
[494] Fix | Delete
[495] Fix | Delete
/** removes a previously added hook
[496] Fix | Delete
*
[497] Fix | Delete
* @param vbase a pointer to either struct evrpc_base or struct evrpc_pool
[498] Fix | Delete
* @param hook_type either INPUT or OUTPUT
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function