/trunk/src/Mono.Zeroconf.Providers.Bonjour/Mono.Zeroconf.Providers.Bonjour/BrowseService.cs |
@@ -58,11 +58,18 @@ |
{ |
resolve_reply_handler = new Native.DNSServiceResolveReply(OnResolveReply); |
query_record_reply_handler = new Native.DNSServiceQueryRecordReply(OnQueryRecordReply); |
resolveAction = new Action<bool>(Resolve); |
} |
|
private Action<bool> resolveAction; |
|
public void Resolve() |
{ |
Resolve(false); |
// If people call this in a ServiceAdded eventhandler (which they genreally do) |
// We need to invoke onto another thread otherwise we block processing any more results. |
|
resolveAction.BeginInvoke(false, null, null); |
} |
|
public void Resolve(bool requery) |
@@ -80,7 +87,7 @@ |
|
ServiceRef sd_ref; |
ServiceError error = Native.DNSServiceResolve(out sd_ref, ServiceFlags.None, |
InterfaceIndex, Name, RegType, ReplyDomain, resolve_reply_handler, IntPtr.Zero); |
InterfaceIndex, Encoding.UTF8.GetBytes(Name), RegType, ReplyDomain, resolve_reply_handler, IntPtr.Zero); |
|
if(error != ServiceError.NoError) { |
throw new ServiceErrorException(error); |
@@ -105,7 +112,7 @@ |
} |
|
private void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string fullname, string hosttarget, ushort port, ushort txtLen, |
ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen, |
IntPtr txtRecord, IntPtr contex) |
{ |
is_resolved = true; |
@@ -112,9 +119,10 @@ |
resolve_pending = false; |
|
InterfaceIndex = interfaceIndex; |
FullName = fullname; |
this.port = port; |
FullName = Native.Utf8toString(fullname); |
this.port = (ushort)IPAddress.NetworkToHostOrder((short)port); |
TxtRecord = new TxtRecord(txtLen, txtRecord); |
this.hosttarget = hosttarget; |
|
sdRef.Deallocate(); |
|
@@ -142,7 +150,16 @@ |
|
sd_ref.Process(); |
} |
|
if (hostentry.AddressList != null) |
{ |
ServiceResolvedEventHandler handler = Resolved; |
if (handler != null) |
{ |
handler(this, new ServiceResolvedEventArgs(this)); |
} |
} |
} |
|
private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, |
ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, |
@@ -150,6 +167,7 @@ |
{ |
switch(rrtype) { |
case ServiceType.A: |
case ServiceType.AAAA: |
IPAddress address; |
|
if(rdlen == 4) { |
@@ -198,8 +216,12 @@ |
break; |
} |
|
|
if ((flags & ServiceFlags.MoreComing) != ServiceFlags.MoreComing) |
{ |
sdRef.Deallocate(); |
} |
} |
|
public bool IsResolved { |
get { return is_resolved; } |