Skip to content
This repository

Use snprintf for resp hdrs, fallback to evbuffer_add_printf

Since evbuffer_add_printf() adds several steps to the evbuffer additions, we
first attempt to use a small stack buffer and snprintf to fill in the response
haeders, and if it fits, we just simply execute evbuffer_add().

If the snprintf fails (not enough space, for some reason), it will fallback to
the original evbuffer_add_printf()
latest commit c27ac5a2c9
Mark Ellzey authored March 23, 2014
Octocat-spinner-32 Makefile More -Wextra mods July 20, 2011
Octocat-spinner-32 README No more submodules July 08, 2011
Octocat-spinner-32 evthr.c Use snprintf for resp hdrs, fallback to evbuffer_add_printf March 23, 2014
Octocat-spinner-32 evthr.h evthr_*set_backlog for SO_RCVBUF sockopts February 11, 2013
Octocat-spinner-32 test.c Added evthr max backlog options. May 23, 2012
Libevthr is an API which manages threads and thread-pools in an event based
manner. This API requires libevent with threading support.

Libevthr works a bit differently than most thread management systems. Instead of
conditional signalling and some type of pre-thread queue, Libevthr uses a
deferral type mechanism. That is, a thread is always running, abstracted to a
point where you "defer" your function *into* a thread. 

For example you can start up a single thread with a backlog of 10 (a backlog
being the max number of outstanding callbacks to run within the thread), and
execute a function you would like to run inside the thread one or many times.
The act of deferrals is non-blocking. 

Example Code for evthrs:

	evthr_t * thr = evthr_new(10, NULL);
	if (evthr_start(thr) < 0) {

	evthr_defer(thr, my_cb_1, NULL);
	evthr_defer(thr, my_cb_2, NULL);
	evthr_defer(thr, my_cb_3, NULL);



Libevthr also has the ability to create pools using the same methods that a 
single evthr has. For example, if you would like to create 10 threads, each
with a backlog of 5: 

	evthr_pool_t * thr_pool = evthr_pool_new(10, 5, NULL);

	if (evthr_pool_start(thr_pool) < 0) {

	evthr_pool_defer(thr_pool, my_cb_1, NULL);
	evthr_pool_defer(thr_pool, my_cb_2, NULL);
	evthr_pool_defer(thr_pool, my_cb_3, NULL);

Your callback functions which you defer must be of type "evthr_cb", or 
"void cb_name(void * arg, void * shared)". In this case, the "arg" variable is
the data you passed as the third argument to either evthr_pool_defer, or
evthr_defer. The "shared" variable is the data that was either the second
variable in evthr_new(), or the third variable in evthr_pool_new().

The gist of this is to allow a global dataset, along with deferred specific

See test.c for a quick example.
Something went wrong with that request. Please try again.