ArchiveOrangemail archive

Avahi ML


avahi.lists.freedesktop.org
(List home) (Recent threads) (85 other Freedesktop.org lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • Low traffic list: less than 3 messages per day
  • This list contains about 2,236 messages, beginning Nov 2004
  • 0 messages added yesterday
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

avahi poll API, level triggered vs edge triggered

Ad
Gaspard Bucher 1331019509Tue, 06 Mar 2012 07:38:29 +0000 (UTC)
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 Bucher 1331038747Tue, 06 Mar 2012 12:59:07 +0000 (UTC)
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,

GaspardOn Tue, Mar 6, 2012 at 8:38 AM, Gaspard Bucher  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
>
>
Home | About | Privacy