[avahi] How to browse services after daemon restart

E-J van der Linden EJvanderLinden at hetnet.nl
Fri May 13 10:16:02 PDT 2011


I solved the problem myself...

I have registered my service in the "Client Registering" state and then the avahi_service_browser_new call does not fail in assertion.

It is a little bit strange and I don't understand it but now it works...
Can somebody explain this?

Correct working version:
> 	+ create a Avahi client (with flag AVAHI_CLIENT_NO_FAIL)
> 	+ create a service browser for _printer._tcp
> 	+ get browser callbacks for printers found

> 	+ restart avahi daemon

> 	+ upon connection lost client callback free the client and create a new Avahi client
> 	+ upon client in state AVAHI_CLIENT_S_REGISTERING: I create a new service browser for _printer._tcp. 

> 	+ get browser callbacks for printers found


Version that runs into assertion:
> 	+ create a Avahi client (with flag AVAHI_CLIENT_NO_FAIL)
> 	+ create a service browser for _printer._tcp
> 	+ get browser callback for printers found

> 	+ 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 for _printer._tcp.
> 	+ then I get a assertion "AvahiTest: browser.c:583: avahi_service_browser_new: Assertion `client' failed."



E-J

Op 12 mei 2011, om 22:04 heeft E-J van der Linden het volgende geschreven:

> 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	
> 		}
> 	}
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/avahi/attachments/20110513/9a06ba29/attachment-0001.html>


More information about the avahi mailing list