Hello,
Say I do something along the line of:
--------------------------------
static void do_error(struct bufferevent *bev, short error, void *ctx)
{
int release = 0;
if(error & BEV_EVENT_EOF)
{
release = 1;
}
else if(error & BEV_EVENT_ERROR)
{
release = 1;
}
if(release)
{
parserctx_t *pctx = ctx;
/* ... */
free(pctx);
bufferevent_free(bev);
}
}
static void do_read(struct bufferevent *bev, void *ctx)
{
struct evbuffer *input;
parserctx_t *pctx = ctx;
/* ... */
input = bufferevent_get_input(bev);
/* ... */
if(got_complete_message)
{
launch_worker_thread(pctx);
}
/* ... */
}
void *worker_thread(parserctx_t *pctx)
{
struct bufferevent *bev = pctx->bev
struct evbuffer *output;
/* ... */
output = bufferevent_get_output(bev);
/* ... */
evbuffer_add_printf(output, "Results: %s", results);
/* ... */
}
--------------------------------
If the client closes the socket, do_error() will release bev, which -
I would assume - cause the worker_thread() to croak next time it
accesses bev/output.
There are a few solutions to this, the one I'm leaning towards is to
not release bev in do_error(), but rather flag it for deletion, and let
worker_thread() do it (if it has started; otherwise do_error() does it).
But it got me wondering if there are some mechanisms in libevent to
assist in these types of situations?
Are there any special caveats with releasing bev in a separate
thread? (Will it cause do_error() to be called on the base thread?).
--
Kind regards,
Jan Danielsson
***********************************************************************
To unsubscribe, send an e-mail to [email protected] with
unsubscribe libevent-users in the body.