From d48cdd18a2fb330bf951834d560cc844cae21383 Mon Sep 17 00:00:00 2001 From: Edwin Wu Date: Mon, 24 Nov 2025 23:23:31 -0800 Subject: [PATCH] Fix the Hotspot upgrade failed. PiperOrigin-RevId: 836521706 --- .../Mediums/WiFiCommon/GNCNWConnection.h | 2 +- .../Mediums/WiFiCommon/GNCNWConnectionImpl.m | 2 +- .../apple/Mediums/WiFiCommon/GNCNWFramework.m | 28 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnection.h b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnection.h index 55c6b3c2..3ca41a47 100644 --- a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnection.h +++ b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnection.h @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN * * @param handler The state changed handler to use for the connection. */ -- (void)setStateChangedHandler:(nw_connection_state_changed_handler_t)handler; +- (void)setStateChangedHandler:(nullable nw_connection_state_changed_handler_t)handler; /** * Starts the connection. diff --git a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnectionImpl.m b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnectionImpl.m index 1c8cb1f3..78036685 100644 --- a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnectionImpl.m +++ b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWConnectionImpl.m @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN nw_connection_set_queue(_connection, queue); } -- (void)setStateChangedHandler:(nw_connection_state_changed_handler_t)handler { +- (void)setStateChangedHandler:(nullable nw_connection_state_changed_handler_t)handler { nw_connection_set_state_changed_handler(_connection, handler); } diff --git a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.m b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.m index 91fbf7d0..7668a6a1 100644 --- a/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.m +++ b/internal/platform/implementation/apple/Mediums/WiFiCommon/GNCNWFramework.m @@ -34,7 +34,7 @@ NS_ASSUME_NONNULL_BEGIN // An arbitrary timeout that should be pretty lenient. -NSTimeInterval const GNCConnectionTimeoutInSeconds = 2; +NSTimeInterval const GNCConnectionTimeoutInSeconds = 4; // This doesn't start flaking until 0.000005 seconds, so 0.5 should be plenty of time. NSTimeInterval const GNCStartDiscoveryTimeoutInSeconds = 0.5; @@ -429,23 +429,23 @@ NSDictionary *GNCTXTRecordForBrowseResult(nw_browse_resu id connectionWrapper = [[GNCNWConnectionImpl alloc] init]; [connectionWrapper createConnectionWithEndpoint:endpoint parameters:parameters]; [connectionWrapper setQueue:queue ?: _dispatchQueue]; - [connectionWrapper - setStateChangedHandler:^(nw_connection_state_t state, nw_error_t error) { - [condition lock]; - // Ignore the preparing state, because it is not a final state. - if (state != nw_connection_state_preparing) { - blockResult = state; - if (error != nil) { - blockError = (__bridge_transfer NSError *)nw_error_copy_cf_error(error); - } - [condition signal]; - } - [condition unlock]; - }]; + [connectionWrapper setStateChangedHandler:^(nw_connection_state_t state, nw_error_t error) { + [condition lock]; + // Ignore the preparing state and waiting state, because it is not a final state. + if ((state != nw_connection_state_preparing) && (state != nw_connection_state_waiting)) { + blockResult = state; + if (error != nil) { + blockError = (__bridge_transfer NSError *)nw_error_copy_cf_error(error); + } + [condition signal]; + } + [condition unlock]; + }]; if (cancelSource) { dispatch_source_set_event_handler(cancelSource, ^{ GNCLoggerInfo( @"[GNCNWFramework] Connection to endpoint was cancelled before it could be established."); + [connectionWrapper setStateChangedHandler:nil]; // Prevent callback issues [connectionWrapper cancel]; dispatch_source_cancel(cancelSource); });