[HELP!] Rev Externals: running a loop without disrupting the stack or inter thread communication

Andre Garzia andre at andregarzia.com
Fri Jul 23 15:17:47 EDT 2010


Folks & Folkettes,

I've written a nice external here which I hope will be the basis of many of
my forthcoming products. My external is a "Embeddable Web Server" just like
Valentina and SQLite are Embeddable Databases. Among other things, it uses a
poll of threads to serve the web requests. My question is related to how to
trigger a callback on the stack when a request comes.

When there's a web request, the external drives it to some of it's threads,
it might start a new one if needed or reuse an old one. Anyway, the thing
is, the code answering the web request probably is running on a different
thread/process (pthreads) than the rev engine and thus that code can't
execute External SDK calls because Rev Engine likes its calls be made only
from the main thread.

What I need is first a way to notify the main thread when a child thread has
something it wants executed in the rev engine. I am thinking about maybe
using pipes for that or message queues. If you want an example on why this
feature is useful, for example, it is useful for binding URLs to Revolution
Handlers/Commands so that when a request comes, we send "NewRequest" to the
main stack for example. You might be thinking "But andre doesn't that
defeats the purpose of having multiple threads since they will all block
trying to talk to rev single-thread engine?", and the answer is "I don't
mean to drive all requests back to rev but to allow some urls to be
connected back to rev so that  you can serve static pages and cgis but also
have some specific urls that can trigger user-defined commands". So for the
external writers among us, using pipes or message queues for inter thread
communication is the best way?

Second question and this probably shows my lack of deep C and Rev Externals
knowledge is, how can we start some "eternal" looping code in the external.
If you think about the question above, it is clear that something in the
main thread needs to be tied to the other end of the pipe or message queue.
This other piece of code might be blocked with select() or poll() waiting
for something to happen, now, if I create an externalCommand like
"webserver_initloop" that starts this loop, wouldn't it block the engine if
the function never returns? If this is confusing let me summarize: How can
some code on the external keep processing while returning the control to rev
at the same time.

By the way, guess whos web server external can load revserver engine and
thus create a portable environment for developing local revserver solutions?
Mine!

:D

PS: If anyone knows anything about this please type a couple of words, I
would hate to release my external without my cherished url binding routine.
We still don't have super good information on external writing so things are
hard.

-- 
http://www.andregarzia.com All We Do Is Code.



More information about the use-livecode mailing list