[avahi] How to browse services after daemon restart

E-J van der Linden EJvanderLinden at hetnet.nl
Thu May 12 13:04:34 PDT 2011


My test is according to this:

	+ create a Avahi client (with flag AVAHI_CLIENT_NO_FAIL)
	+ create a service browser
	+ get browser callback
	+ restart avahi daemon
	+ upon connection lost client callback free the client and create a new Avahi client
	+ upon client in state AVAHI_CLIENT_S_RUNNING: I create a new service browser.
	+ then I get a assertion "AvahiTest: browser.c:583: avahi_service_browser_new: Assertion `client' failed."

Could somebody tell me how I register for new services after the daemon was down and coming up again?

Here are the details:

I create a client

  glib_poll 	= avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);		// Create the GLIB Adaptor
  poll_api 		= avahi_glib_poll_get (glib_poll);
  
  // Create a new AvahiClient instance
  gClient = avahi_client_new (	poll_api,             
			                             	AVAHI_CLIENT_NO_FAIL,
          						avahi_client_callback,	
          						NULL,      		        	
          						&error);              	

** Message: Avahi Client State Change: 2
** Message: Client running; connected to the Avahi Daemon


Then I create a service browser

	gSb = avahi_service_browser_new(gClient, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_printer._tcp", NULL, 0, browse_callback, gClient );


Now I get browse callbacks for services of type _printer._tcp which I can resolve.


Now I restart the avahi daemon and I get client callbacks from the different states:

** Message: Avahi Client State Change: 100
** Message: Disconnected from the Avahi Daemon: Daemon connection failed
** Message: Avahi Client State Change: 101
** Message: Client is connecting to the Avahi Daemon
** Message: Avahi Client State Change: 1
** Message: Client registering
** Message: Avahi Client State Change: 2
** Message: Client running; connected to the Avahi Daemon

I release the client upon disconnection and then I start a new one.

 glib_poll 	= avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);		// Create the GLIB Adaptor
  poll_api 		= avahi_glib_poll_get (glib_poll);
  
  // Create a new AvahiClient instance
  gClient = avahi_client_new (	poll_api,             
			                             	AVAHI_CLIENT_NO_FAIL,
          						avahi_client_callback,
          						NULL,      		 
          						&error);              	


When the client is again in state AVAHI_CLIENT_S_RUNNING, I start a new browser for the _printer._tcp service when we are connected to the daemon
Then I get the following assertion:

AvahiTest: browser.c:583: avahi_service_browser_new: Assertion `client' failed.

This is my client callback:

	switch (state) {
	
		case AVAHI_CLIENT_FAILURE:
		{
			g_message ("Disconnected from the Avahi Daemon: %s", avahi_strerror(avahi_client_errno(client)));
		   	avahi_client_free (gClient);		  
			lResult = AvahiLibStartClient();
			break;
		}
		case AVAHI_CLIENT_CONNECTING:
		{
		  	g_message ("Client is connecting to the Avahi Daemon");		
			break;
		}

		case AVAHI_CLIENT_S_RUNNING:
		{
		  	g_message ("Client running; connected to the Avahi Daemon");		
			gSb = avahi_service_browser_new(gClient, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_printer._tcp", NULL, 0, browse_callback, gClient );
			break;
		}	
		case AVAHI_CLIENT_S_REGISTERING:
		{
		  	g_message ("Client registering");		
		  	break;
		}		
		case AVAHI_CLIENT_S_COLLISION:
		{
		  	g_message ("Client collision");		
		  	break;
		}		
		default:
		{
		  	g_message ("Client to an undefined state?");		
			// no action	
		}
	}




More information about the avahi mailing list