# HG changeset patch # User jim@Baldrick.local # Date 1241591090 25200 # Node ID aab592ac36fc5830da0b4f05d4d08e732e38e863 # Parent a9c59b0acbbcb28e9397e8a5dc48a58688b66500 bug fixes and improvements to new bonjour classes and tcplistener, also added a static library target diff -r a9c59b0acbbc -r aab592ac36fc Bonjour/MYAddressLookup.m --- a/Bonjour/MYAddressLookup.m Wed Apr 29 21:05:01 2009 -0700 +++ b/Bonjour/MYAddressLookup.m Tue May 05 23:24:50 2009 -0700 @@ -25,7 +25,7 @@ return nil; } _hostname = [hostname copy]; - _addresses = [[NSMutableArray alloc] init]; + _addresses = [[NSMutableSet alloc] init]; } return self; } @@ -62,10 +62,24 @@ if (address) { if (flags & kDNSServiceFlagsAdd) { LogTo(DNS,@"%@ got %@ [TTL = %u]", self, address, ttl); + NSSet *changedObjects = [NSSet setWithObject:address]; + [self willChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueUnionSetMutation + usingObjects:changedObjects]; [_addresses addObject: address]; + [self didChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueUnionSetMutation + usingObjects:changedObjects]; } else { LogTo(DNS,@"%@ lost %@ [TTL = %u]", self, address, ttl); + NSSet *changedObjects = [NSSet setWithObject:address]; + [self willChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueMinusSetMutation + usingObjects:changedObjects]; [_addresses removeObject: address]; + [self didChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueMinusSetMutation + usingObjects:changedObjects]; } [address release]; } @@ -96,7 +110,16 @@ - (DNSServiceErrorType) createServiceRef: (DNSServiceRef*)sdRefPtr { - [_addresses removeAllObjects]; + if ([_addresses count] > 0) { + NSSet *changedObjects = [NSSet setWithSet:_addresses]; + [self willChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueMinusSetMutation + usingObjects:changedObjects]; + [_addresses removeAllObjects]; + [self didChangeValueForKey:@"addresses" + withSetMutation:NSKeyValueMinusSetMutation + usingObjects:changedObjects]; + } return DNSServiceGetAddrInfo(sdRefPtr, kDNSServiceFlagsShareConnection, _interfaceIndex, 0, diff -r a9c59b0acbbc -r aab592ac36fc Bonjour/MYBonjourService.h --- a/Bonjour/MYBonjourService.h Wed Apr 29 21:05:01 2009 -0700 +++ b/Bonjour/MYBonjourService.h Tue May 05 23:24:50 2009 -0700 @@ -54,6 +54,7 @@ /** Returns a MYDNSLookup object that resolves the raw IP address(es) of this service. Subsequent calls to this method will always return the same object. */ - (MYAddressLookup*) addressLookup; +- (MYAddressLookup*) addressLookupObservingNewAddresses:(NSObject *)observer; //@} diff -r a9c59b0acbbc -r aab592ac36fc Bonjour/MYBonjourService.m --- a/Bonjour/MYBonjourService.m Wed Apr 29 21:05:01 2009 -0700 +++ b/Bonjour/MYBonjourService.m Tue May 05 23:24:50 2009 -0700 @@ -232,8 +232,7 @@ &resolveCallback, self); } - -- (MYAddressLookup*) addressLookup { +- (MYAddressLookup*) addressLookupObservingNewAddresses:(NSObject *)observer { if (!_addressLookup) { // Create the lookup the first time this is called: _addressLookup = [[MYAddressLookup alloc] initWithHostname: self.hostname]; @@ -241,10 +240,17 @@ _addressLookup.interfaceIndex = _interfaceIndex; } // (Re)start the lookup if it's expired: - if (_addressLookup && _addressLookup.timeToLive <= 0.0) + if (_addressLookup && _addressLookup.timeToLive <= 0.0) { + if (observer != nil) { + [_addressLookup addObserver:observer forKeyPath:@"addresses" options:NSKeyValueObservingOptionNew context:NULL]; + } [_addressLookup start]; + } return _addressLookup; } +- (MYAddressLookup*) addressLookup { + return [self addressLookupObservingNewAddresses:nil]; +} - (MYBonjourQuery*) queryForRecord: (UInt16)recordType { diff -r a9c59b0acbbc -r aab592ac36fc MYNetwork-iPhone.xcodeproj/project.pbxproj --- a/MYNetwork-iPhone.xcodeproj/project.pbxproj Wed Apr 29 21:05:01 2009 -0700 +++ b/MYNetwork-iPhone.xcodeproj/project.pbxproj Tue May 05 23:24:50 2009 -0700 @@ -48,6 +48,40 @@ 27D915CB0FA8EAD0002B0DEC /* MYBonjourQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C60FA8EAD0002B0DEC /* MYBonjourQuery.m */; }; 27D915CC0FA8EAD0002B0DEC /* MYBonjourRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C80FA8EAD0002B0DEC /* MYBonjourRegistration.m */; }; 280E754F0DD40C5E005A515E /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 280E754C0DD40C5E005A515E /* MainWindow.xib */; }; + 384A72AE0FB00523006A0B19 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1D30AB110D05D00D00671497 /* Foundation.framework */; }; + 384A72AF0FB00523006A0B19 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 270E9B4E0EE63F8F003F17CA /* CFNetwork.framework */; }; + 384A72B00FB00523006A0B19 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 270E9AE80EE61167003F17CA /* libz.dylib */; }; + 384A72B10FB00523006A0B19 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1DF5F4DF0D08C38300B7A737 /* UIKit.framework */; }; + 384A72B20FB00523006A0B19 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2777C78C0F75E141007F8D30 /* Security.framework */; }; + 384A72B70FB0062C006A0B19 /* ConcurrentOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 384A72B60FB0062C006A0B19 /* ConcurrentOperation.m */; }; + 384A72B80FB006DF006A0B19 /* IPAddress.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AA20EE61113003F17CA /* IPAddress.m */; }; + 384A72B90FB006DF006A0B19 /* TCPConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AA50EE61113003F17CA /* TCPConnection.m */; }; + 384A72BA0FB006DF006A0B19 /* TCPEndpoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AA70EE61113003F17CA /* TCPEndpoint.m */; }; + 384A72BB0FB006DF006A0B19 /* TCPListener.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AA90EE61113003F17CA /* TCPListener.m */; }; + 384A72BC0FB006DF006A0B19 /* TCPStream.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AAB0EE61113003F17CA /* TCPStream.m */; }; + 384A72BD0FB006DF006A0B19 /* TCPWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AAD0EE61113003F17CA /* TCPWriter.m */; }; + 384A72BE0FB006DF006A0B19 /* BLIPConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AB20EE61113003F17CA /* BLIPConnection.m */; }; + 384A72BF0FB006DF006A0B19 /* BLIPDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AB40EE61113003F17CA /* BLIPDispatcher.m */; }; + 384A72C00FB006DF006A0B19 /* BLIPMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AB60EE61113003F17CA /* BLIPMessage.m */; }; + 384A72C10FB006DF006A0B19 /* BLIPRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AB80EE61113003F17CA /* BLIPRequest.m */; }; + 384A72C20FB006DF006A0B19 /* BLIPProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9ABA0EE61113003F17CA /* BLIPProperties.m */; }; + 384A72C30FB006DF006A0B19 /* BLIPReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9ABC0EE61113003F17CA /* BLIPReader.m */; }; + 384A72C40FB006DF006A0B19 /* BLIPWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9ABE0EE61113003F17CA /* BLIPWriter.m */; }; + 384A72C50FB006DF006A0B19 /* CollectionUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AD10EE6111A003F17CA /* CollectionUtils.m */; }; + 384A72C60FB006DF006A0B19 /* ExceptionUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AD30EE6111A003F17CA /* ExceptionUtils.m */; }; + 384A72C70FB006DF006A0B19 /* Logging.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AD50EE6111A003F17CA /* Logging.m */; }; + 384A72C80FB006DF006A0B19 /* Target.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AD70EE6111A003F17CA /* Target.m */; }; + 384A72C90FB006DF006A0B19 /* Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9AD90EE6111A003F17CA /* Test.m */; }; + 384A72CA0FB006DF006A0B19 /* GTMNSData+zlib.m in Sources */ = {isa = PBXBuildFile; fileRef = 270E9ADD0EE6111A003F17CA /* GTMNSData+zlib.m */; }; + 384A72CB0FB006DF006A0B19 /* MYPortMapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 278C1B2C0F9F865800954AE1 /* MYPortMapper.m */; }; + 384A72CC0FB006DF006A0B19 /* PortMapperTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 278C1B2D0F9F865800954AE1 /* PortMapperTest.m */; }; + 384A72CD0FB006DF006A0B19 /* MYDNSService.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915BC0FA8EABC002B0DEC /* MYDNSService.m */; }; + 384A72CE0FB006DF006A0B19 /* MYAddressLookup.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915BE0FA8EABC002B0DEC /* MYAddressLookup.m */; }; + 384A72CF0FB006DF006A0B19 /* MYBonjourBrowser.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C20FA8EAD0002B0DEC /* MYBonjourBrowser.m */; }; + 384A72D00FB006DF006A0B19 /* MYBonjourService.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C40FA8EAD0002B0DEC /* MYBonjourService.m */; }; + 384A72D10FB006DF006A0B19 /* MYBonjourQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C60FA8EAD0002B0DEC /* MYBonjourQuery.m */; }; + 384A72D20FB006DF006A0B19 /* MYBonjourRegistration.m in Sources */ = {isa = PBXBuildFile; fileRef = 27D915C80FA8EAD0002B0DEC /* MYBonjourRegistration.m */; }; + 384A72D30FB006DF006A0B19 /* ConcurrentOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 384A72B60FB0062C006A0B19 /* ConcurrentOperation.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -127,6 +161,9 @@ 27D915C80FA8EAD0002B0DEC /* MYBonjourRegistration.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MYBonjourRegistration.m; path = Bonjour/MYBonjourRegistration.m; sourceTree = ""; }; 280E754C0DD40C5E005A515E /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = ""; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = iPhone/main.m; sourceTree = ""; }; + 384A72A90FB0050B006A0B19 /* libMYNetwork.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMYNetwork.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 384A72B50FB0062C006A0B19 /* ConcurrentOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConcurrentOperation.h; sourceTree = ""; }; + 384A72B60FB0062C006A0B19 /* ConcurrentOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConcurrentOperation.m; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ @@ -143,6 +180,18 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 384A72A70FB0050B006A0B19 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 384A72AE0FB00523006A0B19 /* Foundation.framework in Frameworks */, + 384A72AF0FB00523006A0B19 /* CFNetwork.framework in Frameworks */, + 384A72B00FB00523006A0B19 /* libz.dylib in Frameworks */, + 384A72B10FB00523006A0B19 /* UIKit.framework in Frameworks */, + 384A72B20FB00523006A0B19 /* Security.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -150,6 +199,7 @@ isa = PBXGroup; children = ( 1D6058910D05DD3D006BFB54 /* BLIPEcho.app */, + 384A72A90FB0050B006A0B19 /* libMYNetwork.a */, ); name = Products; sourceTree = ""; @@ -220,6 +270,8 @@ 270E9ACD0EE6111A003F17CA /* MYUtilities */ = { isa = PBXGroup; children = ( + 384A72B50FB0062C006A0B19 /* ConcurrentOperation.h */, + 384A72B60FB0062C006A0B19 /* ConcurrentOperation.m */, 270E9ACE0EE6111A003F17CA /* MYUtilitiesTest_main.m */, 270E9ACF0EE6111A003F17CA /* MYUtilities_Prefix.pch */, 270E9AD00EE6111A003F17CA /* CollectionUtils.h */, @@ -345,6 +397,16 @@ }; /* End PBXGroup section */ +/* Begin PBXHeadersBuildPhase section */ + 384A72A50FB0050B006A0B19 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + /* Begin PBXNativeTarget section */ 1D6058900D05DD3D006BFB54 /* MYNetwork-iPhone */ = { isa = PBXNativeTarget; @@ -363,6 +425,23 @@ productReference = 1D6058910D05DD3D006BFB54 /* BLIPEcho.app */; productType = "com.apple.product-type.application"; }; + 384A72A80FB0050B006A0B19 /* MYNetwork */ = { + isa = PBXNativeTarget; + buildConfigurationList = 384A72B40FB00534006A0B19 /* Build configuration list for PBXNativeTarget "MYNetwork" */; + buildPhases = ( + 384A72A50FB0050B006A0B19 /* Headers */, + 384A72A60FB0050B006A0B19 /* Sources */, + 384A72A70FB0050B006A0B19 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MYNetwork; + productName = MYNetwork; + productReference = 384A72A90FB0050B006A0B19 /* libMYNetwork.a */; + productType = "com.apple.product-type.library.static"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -383,6 +462,7 @@ projectRoot = ""; targets = ( 1D6058900D05DD3D006BFB54 /* MYNetwork-iPhone */, + 384A72A80FB0050B006A0B19 /* MYNetwork */, ); }; /* End PBXProject section */ @@ -438,6 +518,42 @@ 27D915CA0FA8EAD0002B0DEC /* MYBonjourService.m in Sources */, 27D915CB0FA8EAD0002B0DEC /* MYBonjourQuery.m in Sources */, 27D915CC0FA8EAD0002B0DEC /* MYBonjourRegistration.m in Sources */, + 384A72B70FB0062C006A0B19 /* ConcurrentOperation.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 384A72A60FB0050B006A0B19 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 384A72B80FB006DF006A0B19 /* IPAddress.m in Sources */, + 384A72B90FB006DF006A0B19 /* TCPConnection.m in Sources */, + 384A72BA0FB006DF006A0B19 /* TCPEndpoint.m in Sources */, + 384A72BB0FB006DF006A0B19 /* TCPListener.m in Sources */, + 384A72BC0FB006DF006A0B19 /* TCPStream.m in Sources */, + 384A72BD0FB006DF006A0B19 /* TCPWriter.m in Sources */, + 384A72BE0FB006DF006A0B19 /* BLIPConnection.m in Sources */, + 384A72BF0FB006DF006A0B19 /* BLIPDispatcher.m in Sources */, + 384A72C00FB006DF006A0B19 /* BLIPMessage.m in Sources */, + 384A72C10FB006DF006A0B19 /* BLIPRequest.m in Sources */, + 384A72C20FB006DF006A0B19 /* BLIPProperties.m in Sources */, + 384A72C30FB006DF006A0B19 /* BLIPReader.m in Sources */, + 384A72C40FB006DF006A0B19 /* BLIPWriter.m in Sources */, + 384A72C50FB006DF006A0B19 /* CollectionUtils.m in Sources */, + 384A72C60FB006DF006A0B19 /* ExceptionUtils.m in Sources */, + 384A72C70FB006DF006A0B19 /* Logging.m in Sources */, + 384A72C80FB006DF006A0B19 /* Target.m in Sources */, + 384A72C90FB006DF006A0B19 /* Test.m in Sources */, + 384A72CA0FB006DF006A0B19 /* GTMNSData+zlib.m in Sources */, + 384A72CB0FB006DF006A0B19 /* MYPortMapper.m in Sources */, + 384A72CC0FB006DF006A0B19 /* PortMapperTest.m in Sources */, + 384A72CD0FB006DF006A0B19 /* MYDNSService.m in Sources */, + 384A72CE0FB006DF006A0B19 /* MYAddressLookup.m in Sources */, + 384A72CF0FB006DF006A0B19 /* MYBonjourBrowser.m in Sources */, + 384A72D00FB006DF006A0B19 /* MYBonjourService.m in Sources */, + 384A72D10FB006DF006A0B19 /* MYBonjourQuery.m in Sources */, + 384A72D20FB006DF006A0B19 /* MYBonjourRegistration.m in Sources */, + 384A72D30FB006DF006A0B19 /* ConcurrentOperation.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -460,6 +576,31 @@ }; name = Release; }; + 384A72AA0FB0050C006A0B19 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = NO; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + PREBINDING = NO; + PRODUCT_NAME = MYNetwork; + }; + name = Debug; + }; + 384A72AB0FB0050C006A0B19 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_ENABLE_FIX_AND_CONTINUE = NO; + PREBINDING = NO; + PRODUCT_NAME = MYNetwork; + ZERO_LINK = NO; + }; + name = Release; + }; C01FCF4F08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 278C1B330F9F86A100954AE1 /* MYUtilities_Debug.xcconfig */; @@ -494,6 +635,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 384A72B40FB00534006A0B19 /* Build configuration list for PBXNativeTarget "MYNetwork" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 384A72AA0FB0050C006A0B19 /* Debug */, + 384A72AB0FB0050C006A0B19 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; C01FCF4E08A954540054247B /* Build configuration list for PBXProject "MYNetwork-iPhone" */ = { isa = XCConfigurationList; buildConfigurations = ( diff -r a9c59b0acbbc -r aab592ac36fc TCP/TCPListener.m --- a/TCP/TCPListener.m Wed Apr 29 21:05:01 2009 -0700 +++ b/TCP/TCPListener.m Tue May 05 23:24:50 2009 -0700 @@ -24,6 +24,7 @@ @interface TCPListener() - (void) _openBonjour; +- (void) _publishBonjour; - (void) _closeBonjour; @property BOOL bonjourPublished; @property NSInteger bonjourError; @@ -248,6 +249,11 @@ #pragma mark - #pragma mark BONJOUR: +// subclasses can override if they want to call publishWithOptions: instead of publish +- (void) _publishBonjour +{ + [_netService publish]; +} - (void) _openBonjour { @@ -261,7 +267,7 @@ [_netService setDelegate:self]; if( _bonjourTXTRecord ) [self _updateTXTRecord]; - [_netService publish]; + [self _publishBonjour]; } else { self.bonjourError = -1; Warn(@"%@: Failed to create NSNetService",self); @@ -322,7 +328,7 @@ } -- (void)netServiceWillPublish:(NSNetService *)sender +- (void)netServiceDidPublish:(NSNetService *)sender { LogTo(BLIP,@"%@: Advertising %@",self,sender); self.bonjourPublished = YES;