* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
callbacks have been registered for a given URI.
@section evrpc A framework for RPC servers and clients
-
+
libevents provides a framework for creating RPC servers and clients. It
takes care of marshaling and unmarshaling all data structures.
def CodeClear(self, structname):
code = [ 'if (%s->%s_set == 1) {' % (structname, self.Name()),
- ' free (%s->%s_data);' % (structname, self.Name()),
+ ' free(%s->%s_data);' % (structname, self.Name()),
' %s->%s_data = NULL;' % (structname, self.Name()),
' %s->%s_set = 0;' % (structname, self.Name()),
'}'
def CodeFree(self, name):
code = ['if (%s->%s_data != NULL)' % (name, self._name),
- ' %s_free(%s->%s_data); ' % (
+ ' %s_free(%s->%s_data);' % (
self._refname, name, self._name)]
return code
def CodeFree(self, name):
code = ['if (%s->%s_data != NULL)' % (name, self._name),
- ' free (%s->%s_data); ' % (name, self._name)]
+ ' free(%s->%s_data);' % (name, self._name)]
return code
continue
if len(tokens[1]):
- raise RpcGenError('Trailing garbage after struct on line %d'
+ raise RpcGenError('Trailing garbage after struct on line %d'
% line_count)
# We found the end of the struct
entry.PrintCode(impl_fp)
impl_fp.close()
-if __name__ == '__main__':
+if __name__ == '__main__':
try:
CommandLine(sys.argv).run()
sys.exit(0)
/* hooks for processing outbound and inbound rpcs */
struct evrpc_hook_list in_hooks;
struct evrpc_hook_list out_hooks;
-
+
struct evrpc_pause_list pause_requests;
};
/* the empty reply object that needs to be filled in */
void *reply;
- /*
+ /*
* the static structure for this rpc; that can be used to
* automatically unmarshal and marshal the http buffers.
*/
int (*rpl_complete)(void *),
void (*rpl_marshal)(struct evbuffer *, void *))
{
- struct evrpc* rpc =
+ struct evrpc* rpc =
evrpc_register_object(name, req_new, req_free, req_unmarshal,
rpl_new, rpl_free, rpl_complete, rpl_marshal);
if (rpc == NULL)
struct bufferevent *bufev;
struct event retry_ev; /* for retrying connects */
-
+
char *bind_address; /* address to use for binding the src */
u_short bind_port; /* local port for binding the src */
int timeout; /* timeout in seconds for events */
int retry_cnt; /* retry count */
int retry_max; /* maximum number of retries */
-
+
enum evhttp_connection_state state;
/* for server connections, the http server they are connected with */
struct evhttp *http_server;
TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
-
+
void (*cb)(struct evhttp_connection *, void *);
void *cb_arg;
-
+
void (*closecb)(struct evhttp_connection *, void *);
void *closecb_arg;
TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
struct evconq connections;
- TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
+ TAILQ_HEAD(vhostsq, evhttp) virtualhosts;
/* NULL if this server is not a vhost */
char *vhost_pattern;
void evhttp_free(struct evhttp* http);
/**
- Set a callback for a specified URI
-
+ Set a callback for a specified URI
+
@param http the http sever on which to set the callback
@param path the path for which to invoke the callback
@param cb the callback function that gets invoked on requesting path
/**
Determines if the member has been set in the message
-
+
@param msg the message to inspect
@param member the member variable to test for presences
@return 1 if it's present or 0 otherwise.
(void (*)(void *))rplystruct##_clear, \
(int (*)(void *, struct evbuffer *))rplystruct##_unmarshal); \
}
-
+
/** Provides access to the HTTP request object underlying an RPC
*
* Access to the underlying http object; can be used to look at headers or
void evrpc_request_done(struct evrpc_req_generic *req);
/** Creates the reply to an RPC request
- *
+ *
* EVRPC_REQUEST_DONE is used to answer a request; the reply is expected
* to have been filled in. The request and reply pointers become invalid
* after this call has finished.
- *
+ *
* @param rpc_req the rpc request structure provided to the server callback
*/
#define EVRPC_REQUEST_DONE(rpc_req) do { \
struct evrpc_req_generic *_req = (struct evrpc_req_generic *)(rpc_req); \
evrpc_request_done(_req); \
} while (0)
-
+
struct evrpc_base;
struct evhttp;
*/
struct evrpc_base *evrpc_init(struct evhttp *server);
-/**
+/**
* Frees the evrpc base
*
* For now, you are responsible for making sure that no rpcs are ongoing.
int evrpc_make_request(struct evrpc_request_wrapper *ctx);
/** creates an rpc connection pool
- *
+ *
* a pool has a number of connections associated with it.
* rpc requests are always made via a pool.
*
* @param pool the pool to which to add the connection
* @param evcon the connection to add to the pool.
*/
-void evrpc_pool_add_connection(struct evrpc_pool *pool,
+void evrpc_pool_add_connection(struct evrpc_pool *pool,
struct evhttp_connection *evcon);
/**
int evrpc_hook_find_meta(void *ctx, const char *key,
void **data, size_t *data_size);
-/**
+/**
* returns the connection object associated with the request
*
* @param ctx the context provided to the hook call
/**
Function for registering a generic RPC with the RPC base.
-
+
Do not call this function directly, use EVRPC_REGISTER() instead.
@see EVRPC_REGISTER()
*/
-/**
+/**
* provides information about the completed RPC request.
*/
struct evrpc_status {
/* verifies that the reply is valid */
int (*reply_complete)(void *);
-
+
/* marshals the reply into a buffer */
void (*reply_marshal)(struct evbuffer*, void *);
}
woff += len;
-
+
if (woff >= sizeof(wbuf)) {
shutdown(fd, SHUT_WR);
if (usepersist)
int towrite = strlen(TEST1)+1;
int len = write(data->pair[0], TEST1, towrite);
- if (len < 0)
+ if (len < 0)
tt_abort_perror("initial write");
else if (len != towrite)
tt_abort_printf(("initial write fell short (%d of %d bytes)",
len, towrite));
-
+
if (shutdown(data->pair[0], SHUT_WR))
tt_abort_perror("initial write shutdown");
static int validate_header(
const struct evkeyvalq* headers,
- const char *key, const char *value)
+ const char *key, const char *value)
{
const char *real_val = evhttp_find_header(headers, key);
tt_assert(real_val != NULL);
struct evkeyvalq headers;
TAILQ_INIT(&headers);
-
+
evhttp_parse_query("http://www.test.com/?q=test", &headers);
tt_want(validate_header(&headers, "q", "test") == 0);
evhttp_clear_headers(&headers);