[avahi] Integrating Avahi into an application with "select" in the main loop

Nathan Huesken avahi at lonely-star.org
Fri Aug 8 07:40:48 PDT 2008

> You have several options that are far more elegant:
> 1) Implement the AvahiPoll structure for your existing event loop,
>    i.e. implement the seven functions defined here:
>    http://avahi.org/download/doxygen/struct_avahi_poll.html
>    Then, pass this struct to avahi_client_new() and the avahi client
>    will call those functions whenever there is a new FD or timeout to
>    sleep on. You should then add a new item to your "struct pollfd"
>    array (in case you uses poll()) or fd_set (in case you use
>    select()) everytime the watch_new() function you implemented is
>    called by the avahi client libraries, and similarly for the other
>    six functions you'd need to implement.

Sound good! I have a question to this methode:
Avahi also tells me what events to wait for, these are.
So exactly the events "poll" deals with.
For compatibility reasons I do not want to use poll but select.
So, I put all the POLLOUT event sockets in the "writefds" and all the others in the "readfds".
Select should return on connection closed or connection error for any socket in the "readfds", correct?

But how do I determine the event type? I do I distinguish between POLLIN, POLLERR and POLLHUP without reading from the socket?
I need this to react with the correct event.

Any Ideas?

More information about the avahi mailing list