Skip to content

Commit

Permalink
Merge pull request #27 from grandcentrix/fix-scan-stability
Browse files Browse the repository at this point in the history
Improve scan stability
  • Loading branch information
James Hutchby authored Jul 20, 2021
2 parents bc1d5f7 + 0df8ffd commit c61e171
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
8 changes: 5 additions & 3 deletions GCXMulticastDNSKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1250;
ORGANIZATIONNAME = "grandcentrix GmbH";
TargetAttributes = {
68FF3C161E24DDDF00A482A8 = {
Expand Down Expand Up @@ -278,6 +278,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -303,7 +304,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -341,6 +342,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand All @@ -360,7 +362,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.2;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -27,6 +27,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "68FF3C161E24DDDF00A482A8"
BuildableName = "GCXMulticastDNSKit.framework"
BlueprintName = "GCXMulticastDNSKit"
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -39,17 +48,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "68FF3C161E24DDDF00A482A8"
BuildableName = "GCXMulticastDNSKit.framework"
BlueprintName = "GCXMulticastDNSKit"
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -70,8 +68,6 @@
ReferencedContainer = "container:GCXMulticastDNSKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
29 changes: 26 additions & 3 deletions GCXMulticastDNSKit/Discovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ extension Discovery {
}
}

/// stops all search and resolve operations, nil out delegates to circumvent http://www.openradar.me/28943305
/// stops all search and resolve operations
private func stopSearchingAndResolving() {
_ = items?.map {
items?.forEach {
$0.netServiceBrowser.stop()
// set delegate to nil to circumvent http://www.openradar.me/28943305
$0.netServiceBrowser.delegate = nil
_ = $0.netServices.map {
$0.netServices.forEach {
$0.stop()
$0.delegate = nil
}
Expand Down Expand Up @@ -285,6 +286,28 @@ extension Discovery: NetServiceBrowserDelegate {
public func netServiceBrowser(_ browser: NetServiceBrowser, didNotSearch errorDict: [String: NSNumber]) {
guard let item = item(serviceBrowser: browser) else { return }

if let errorCode = errorDict[NetService.errorCode] as? Int {
if let netServiceError = NetService.ErrorCode(rawValue: errorCode) {
switch netServiceError {
// when unknown error is received, browsing has stopped and must be restarted.
// this happens when the app suspends/resumes
case .unknownError:
// notify the caller that all existing discovered services have dissapeared
for service in item.netServices {
notifyDiscoveryServiceDidDisappear(service: DiscoveryService(configuration: item.configuration, netService: service))
}
// immediately restart discovery
self.startDiscovery()

// don't send .browsingFailure
return
default:
break
}
}
}

// other failures should be returned because it could be a configuration error
notifyDiscoveryDidFail(configuration: item.configuration, error: .browsingFailure)
}

Expand Down

0 comments on commit c61e171

Please sign in to comment.