[getdns-users] PHP Language Bindings and Async Event Management

Willem Toorop willem at nlnetlabs.nl
Tue Apr 21 15:10:51 UTC 2015


Hi Scott,

With our getdns implementation, the extensions are wrappers that provide
a uniform interface for different event bases.  We provide extensions
for libevent, libev and libuv.  We also have a built in event base
(mini_event) based on select, that will we the default extension when
you did not set one explicitly with getdns_extension_set_libevent_base,
getdns_extension_set_libev_loop and getdns_extension_set_libuv_loop.

All those extension provide their uniform interface through a list of
function pointers with the same signature (the virtual method table
(hence vmt)) in another struct which might have extension specific data
(like the event base itself where the extension provides the uniform
interface for).  So they are actually objects for the getdns_eventloop
class...

One of the functions in the VMT is the cleanup function which will
destroy the extension, but in case of the libevent, libev and libuv
extension, not the event bases with which the extension was created and
set.  Only with mini_event there was no event base on which the
extension was based, so that will destroy the event base with the extension.

I think this answers everything you wanted to know about this, but there
is something else interesting too.

Our implementation provides means to create an event base extension
yourself.  In fact, the node bindings use this to hook into the node
native libuv event loop (so it does not use the libuv extension!).
I do not know how async operation is handled with php normally, but to
just give an example for its potential (which might event not be
realistic)... If we could provide python bindings for those methods to
create your own extension, it might be possible to hook into native
python event systems, like twisted.

Food for thought ;)

Cheers,
-- Willem





Op 21-04-15 om 13:30 schreef Hollenbeck, Scott:
>> -----Original Message-----
>> From: getdns-api [mailto:getdns-api-bounces at vpnc.org] On Behalf Of
>> Goyal, Neel
>> Sent: Monday, April 20, 2015 1:58 PM
>> To: Melinda Shore; getdns-api at vpnc.org
>> Subject: Re: [getdns-api] PHP Language Bindings and Async Event
>> Management
>>
>> Freeing the context should not clean up the event base.  If the event
>> base
>> is shared between other async libs and they are adding to that event
>> base,
>> a context destroy should not prevent those libs from still functioning.
>> The context_destroy makes sure the context is detached from the
>> event_base, but any structures specific to libevent are not cleaned up.
>> Much like the user has to create the lib event base explicitly and then
>> attach it to getdns, the user has to free it.
> 
> Neel, in a note I sent to this list last week (BTW, it looks like recent notes aren't being archived) I described a challenge I found in trying to use the PHP libevent extension with getdns. I can create an event base, but I don't see an easy way to attach that to a context. Come on down if you have a chance and I'll walk you through what I found.
> 
> So, I took a look at how I could use the functions provided by the getdns libevent extension. Looking at the code in context.c, I found that getdns_context_create() calls getdns_context_create_with_memory_functions(), which calls getdns_context_create_with_extended_memory_functions(). That function calls getdns_mini_event_init() (in file libmini_event.c), which creates an event base and sets an event loop. That base is cleaned up when calling getdns_context_destroy(), which calls context->extension->vmt->cleanup(context->extension).
> 
> Scott
> 
> _______________________________________________
> getdns-api mailing list
> getdns-api at vpnc.org
> 




More information about the Users mailing list