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

Nathan Huesken avahi at lonely-star.org
Tue Aug 12 03:41:23 PDT 2008


It seems avahi never requests events different form POLLIN and POLLOUT from me. So using select seems to be no problem ...


On Fri, Aug 08, 2008 at 04:40:48PM +0200, Nathan Huesken wrote:
> > 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?
> Thanks!
> Nathan
> _______________________________________________
> avahi mailing list
> avahi at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/avahi

More information about the avahi mailing list