Bonjour/MYBonjourService.m
changeset 57 998dcacd4983
parent 44 d8a559a39284
child 59 46c7844cb592
     1.1 --- a/Bonjour/MYBonjourService.m	Wed May 06 09:21:57 2009 -0700
     1.2 +++ b/Bonjour/MYBonjourService.m	Thu Jul 02 20:45:11 2009 -0700
     1.3 @@ -21,6 +21,8 @@
     1.4  
     1.5  
     1.6  @interface MYBonjourService ()
     1.7 +@property (copy) NSString *hostname;
     1.8 +@property UInt16 port;
     1.9  @end
    1.10  
    1.11  
    1.12 @@ -60,7 +62,8 @@
    1.13  }
    1.14  
    1.15  
    1.16 -@synthesize name=_name, type=_type, domain=_domain, fullName=_fullName, interfaceIndex=_interfaceIndex;
    1.17 +@synthesize name=_name, type=_type, domain=_domain, fullName=_fullName,
    1.18 +            hostname=_hostname, port=_port, interfaceIndex=_interfaceIndex;
    1.19  
    1.20  
    1.21  - (NSString*) description {
    1.22 @@ -105,21 +108,15 @@
    1.23  }
    1.24  
    1.25  
    1.26 -- (void) priv_finishResolve {
    1.27 -    // If I haven't finished my resolve yet, run it *synchronously* now so I can return a valid value:
    1.28 +- (NSString*) hostname {
    1.29      if (!_startedResolve )
    1.30          [self start];
    1.31 -    if (self.serviceRef)
    1.32 -        [self waitForReply];
    1.33 -}    
    1.34 -
    1.35 -- (NSString*) hostname {
    1.36 -    if (!_hostname) [self priv_finishResolve];
    1.37      return _hostname;
    1.38  }
    1.39  
    1.40  - (UInt16) port {
    1.41 -    if (!_port) [self priv_finishResolve];
    1.42 +    if (!_startedResolve )
    1.43 +        [self start];
    1.44      return _port;
    1.45  }
    1.46  
    1.47 @@ -185,16 +182,19 @@
    1.48      LogTo(Bonjour, @"%@: hostname=%@, port=%u, txt=%u bytes", 
    1.49            self, hostname, port, txtData.length);
    1.50  
    1.51 -    // Don't call a setter method to set these properties: the getters are synchronous, so
    1.52 -    // I might already be blocked in a call to one of them, in which case creating a KV
    1.53 -    // notification could cause trouble...
    1.54 -    _hostname = hostname.copy;
    1.55 -    _port = port;
    1.56 +    if (port!=_port || !$equal(hostname,_hostname)) {
    1.57 +        self.hostname = hostname;
    1.58 +        self.port = port;
    1.59 +    }
    1.60      
    1.61 -    // TXT getter is async, though, so I can use a setter to announce the data's availability:
    1.62      [self setTxtData: txtData];
    1.63  }
    1.64  
    1.65 +- (void) gotResponse: (DNSServiceErrorType)errorCode {
    1.66 +    [super gotResponse: errorCode];
    1.67 +    [_addressLookup _serviceGotResponse];
    1.68 +}
    1.69 +
    1.70  
    1.71  static void resolveCallback(DNSServiceRef                       sdRef,
    1.72                              DNSServiceFlags                     flags,
    1.73 @@ -236,8 +236,7 @@
    1.74  - (MYAddressLookup*) addressLookup {
    1.75      if (!_addressLookup) {
    1.76          // Create the lookup the first time this is called:
    1.77 -        _addressLookup = [[MYAddressLookup alloc] initWithHostname: self.hostname];
    1.78 -        _addressLookup.port = _port;
    1.79 +        _addressLookup = [[MYAddressLookup alloc] _initWithBonjourService: self];
    1.80          _addressLookup.interfaceIndex = _interfaceIndex;
    1.81      }
    1.82      // (Re)start the lookup if it's expired: