Skip to content

Commit ef5a63f

Browse files
authored
fix(iOS): defer startTLS until didConnectToHost (#217)
1 parent f166efa commit ef5a63f

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎ios/TcpSocketClient.m‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ @interface TcpSocketClient () {
6666
long _sendTag;
6767
SecTrustRef _peerTrust;
6868
SecIdentityRef _clientIdentity;
69+
NSDictionary *_tlsOptionsPending;
6970
}
7071

7172
- (id)initWithClientId:(NSNumber *)clientID
@@ -164,7 +165,7 @@ - (BOOL)connect:(NSString *)host
164165
error:error];
165166
}
166167
if (result && tlsOptions) {
167-
[self startTLS:tlsOptions];
168+
_tlsOptionsPending = [tlsOptions copy]; // Save for later
168169
}
169170
return result;
170171
}
@@ -572,9 +573,15 @@ - (void)socket:(GCDAsyncSocket *)sock
572573
return;
573574
}
574575

575-
// Show up if SSL handsake is done
576+
// Show up if SSL handshake is done
576577
if (!_tls) {
577-
[_clientDelegate onConnect:self];
578+
if (_tlsOptionsPending) {
579+
[self startTLS:_tlsOptionsPending];
580+
_tlsOptionsPending = nil;
581+
} else {
582+
[_clientDelegate onConnect:self];
583+
_connecting = false;
584+
}
578585
}
579586
[sock readDataWithTimeout:-1 tag:_id.longValue];
580587
}

0 commit comments

Comments
 (0)