[avahi] avahi poll API, level triggered vs edge triggered

Gaspard Bucher gaspard at teti.ch
Tue Mar 6 04:58:53 PST 2012


Hi there !

It seems the problem was not related to edge/level triggering. The Lua
bindings now work correctly with ZeroMQ.

To ease avahi adoption by other users, I think a couple of things could be
improved:

1. Better documentation of the AvahiPoll API. For example, I had to read
the sources to understand that the void *userdata passed to AvahiWatch is
*NOT* the void *userdata that I passed to avahi_client_new.
2. Better documentation of what the entry groups are and why they are
needed.
3. A way to work with raw TXT data in avahi_entry_group_add_service and the
resolution callback to avoid learning a non-documented string list API by
reading strlst.c. Something like "const char *txt, size_t txt_len" is easy
to understand and use.

On the API side, I wonder if there is a way to simply things. To compare,
here are the number of lines of code for the same functionality using
dns-sd on mac or avahi on linux:

dns-sd (mac): 345 lines of code
avahi (linux): 569 lines of code

Code needed once in Lua: less then 10 lines of code

-- Registration
registration = mdns.Registration('_http._tcp', 'my server', 4545, {some =
'txt', content = 12}, function(self, service)
  print('Service registered with name:', service.name)
end)

-- Browsing
browser = mdns.Browser('_http._tcp', function(self, service)
  print(service.op, service.name)
end)

Dream code in C++:

avahi::Publish *pub = new avahi::Publish("_http._tcp", "my server", 4545,
txt_len, txt);
int fd = reg->fd();
// wait read in select
status = reg->status();
name = reg->name();
// ... etc

avahi::Browser *browser = new avahi::Browser("_http._tcp");
int fd = browser->fd();
// wait read on fd by inserting it into a select
while (!browser->empty()) {
  Service s = browser->pop();
  printf("%s '%s'", s.add ? "+" : "-", s.name);
}

Cheers,

Gaspard


On Tue, Mar 6, 2012 at 8:38 AM, Gaspard Bucher <gaspard at teti.ch> wrote:

> Hi list !
>
> I am having a very difficult time creating an AvahiPoll API that should be
> used with an edge triggered event loop (zeroMQ).
>
> I must confess that I do not understand why the Avahi API is so
> complicated (compared with dns-sd which is already not trivial). Why can't
> we simply connect to the daemon with a socket (once for each
> registration/browse) ? We would then only need one file descriptor per
> operation and either block on recv or insert the file descriptor in an
> event loop. This is the abstraction that dns-sd manages to provide with
> DNSServiceRefSockFD.
>
> Anyway, before I start to fork and create pipes, I suspect my API to not
> work because of this edge vs level triggering. Is there a way to "empty"
> the content of newly created AvahiWatch and AvahiTimeout before registering
> the file descriptors inside the poll loop ?
>
> Cheers,
>
>                                                                Gaspard
>
>


-- 

                                                               Gaspard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/avahi/attachments/20120306/feb7d026/attachment.html>


More information about the avahi mailing list