drizzle-discuss team mailing list archive
Mailing list archive
libdrizzle: integration with another event loop
I've been looking into connecting to Drizzle/MySQL via libdrizzle. My
application is a (mostly) single-threaded and event driven, using
libevent. I'm trying to figure out how to integrate libdrizzle with my
own non-blocking event loop. There are a number of approaches I'm
considering. Feedback appreciated.
My initial idea:
Spawn a "libdrizzle event thread", which will call drizzle_con_wait()
in a loop. This can append events to a thread-safe queue, and wake my
main event thread via a socketpair(). My main event thread will use
libdrizzle to send queries and get responses.
* Is libdrizzle thread-safe to use in this fashion? I think the answer
is "no," since the documentation states you can only use a drizzle_st
from one thread.
* Is it possible to get the sockets being used by libdrizzle? It might
be possible to add them to my own libevent loop, and call libdrizzle
when there is stuff to do, rather than relying on drizzle_con_wait()
to block. This would be relatively straightforward for reads, but is
tricky in the case of "write blocked" events, since they need to be
turned on and off on demand.
It looks like I probably need to do this the "old fashioned" way: I
need to do all my libdrizzle work in a separate libdrizzle thread, and
communicate with it and my main event loop.
* Is there a way to wake a thread blocked in drizzle_con_wait()? I
will need this to implement the above technique. I'm willing to
implement a "wakeup via socketpair()" API, if that seems appropriate?
Thanks for your help,