Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Arkane.Zeroconf/IResolvableService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#region using

using System.Net ;
using System.Threading ;
using System.Threading.Tasks ;

#endregion

Expand All @@ -30,4 +32,6 @@ public interface IResolvableService : IService
event ServiceResolvedEventHandler Resolved ;

void Resolve () ;

Task ResolveAsync (CancellationToken cancellationToken = default) ;
}
20 changes: 16 additions & 4 deletions Arkane.Zeroconf/Providers/Bonjour/BrowseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System.Net ;
using System.Runtime.InteropServices ;
using System.Text ;
using System.Threading ;
using System.Threading.Tasks ;

#endregion

Expand All @@ -28,8 +30,8 @@ public BrowseService (string name, string replyDomain, string regtype) : base (n

private Native.DNSServiceQueryRecordReply queryRecordReplyHandler ;

private Action <bool> resolveAction ;
private bool resolvePending ;
private Action <bool, CancellationToken> resolveAction ;
private bool resolvePending ;

private Native.DNSServiceResolveReply resolveReplyHandler ;

Expand All @@ -43,7 +45,12 @@ public void Resolve ()
{
// If people call this in a ServiceAdded event handler (which they generally do), we need to
// invoke onto another thread, otherwise we block processing any more results.
this.resolveResult = this.resolveAction.BeginInvoke (false, null, null) ;
this.resolveResult = ResolveAsync () ;
}

public Task ResolveAsync (CancellationToken cancellationToken = default)
{
return Task.Run (() => this.resolveAction (false, cancellationToken), cancellationToken) ;
}

~BrowseService ()
Expand All @@ -60,6 +67,11 @@ private void SetupCallbacks ()
}

public void Resolve (bool requery)
{
Resolve (requery, CancellationToken.None) ;
}

public void Resolve (bool requery, CancellationToken cancellationToken)
{
if (this.resolvePending)
return ;
Expand All @@ -82,7 +94,7 @@ public void Resolve (bool requery)
if (error != ServiceError.NoError)
throw new ServiceErrorException (error) ;

sdRef.Process () ;
sdRef.Process (cancellationToken) ;
}

public void RefreshTxtRecord ()
Expand Down
13 changes: 11 additions & 2 deletions Arkane.Zeroconf/Providers/Bonjour/ServiceRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#region using

using System ;
using System.Threading ;

#endregion

Expand All @@ -25,8 +26,16 @@ public struct ServiceRef

public void Process ()
{
while (this.ProcessSingle () == ServiceError.NoError)
{ }
Process(CancellationToken.None);
}

public void Process (CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
while (this.ProcessSingle() == ServiceError.NoError)
{
cancellationToken.ThrowIfCancellationRequested();
}
}

public int SocketFD => Native.DNSServiceRefSockFD (this.Raw) ;
Expand Down