Sunday 3 May 2009

Fun with Bonjour and NSRunLoop

You know, I keep coming back to not liking much of the implementation behind Cocoa, no matter how much I use it!

Here is the sort of thing that irritates me. I create a dialog within Mixtikl (using our own internal GUI framework), and run it modally. Within that Dialog, I use Cocoa services to request to be told what Bonjour-advertised services are available. What do I get? Well, nothing, other than a call through the delegate to tell me that searching has started.

It turns out that the processing behind the scenes works only if the active NSRunLoop is allowed to do processing; so I've had to add-in a call like this in my modal loop:


[[NSRunLoop currentRunLoop] limitDateForMode:NSDefaultRunLoopMode];


So you might ask, what is wrong with this? I contend that for such processing, the system should be smarter and use an approach that doesn't require specific magic within the client code (in this case, a worker thread that does the work without my having to worry about blocking it). Otherwise, people who know a lot less than me might never be able to figure-out what they've done wrong.

Bonjour is a great idea, and is built-in to Mac/iPhone: however, I can't spot any open-source implementation that I can use for other platforms. If any reader would be kind enough to point me to such an implementation, I'd love to take a look!

3 comments:

gregor said...

http://developer.apple.com/opensource/internet/bonjour.html

"The open source mDNSResponder project contains the Bonjour service discovery implemenation that's built into Mac OS X and Bonjour for Windows. Additionally, this project contains the mDNSResponder daemon for POSIX and the Java libraries for all platforms."

The mDNSResponder daemon source code is licensed under the terms of the Apache License, Version 2.0. To accommodate compatibility with the widest possible range of client source code licenses, the DNS-SD shared library source code is licensed under the "Three-Clause BSD License".

Perhaps thats not what you're looking for, if so, apologies.

Pete Cole said...

Hey Gregor, that is very useful. Many thanks for taking the trouble to let me know. :)

Pete

Tyler said...

I've seen similar problems in other areas in iPhone OS - mostly UI drawing and timing:

http://bynomial.com/blog/?p=15