diff --git a/Source/GCD/GCDAsyncSocket.m b/Source/GCD/GCDAsyncSocket.m index f3d1c171..1769f7a4 100755 --- a/Source/GCD/GCDAsyncSocket.m +++ b/Source/GCD/GCDAsyncSocket.m @@ -1077,6 +1077,7 @@ + (nullable instancetype)socketFromConnectedSocketFD:(int)socketFD delegate:(nul + (nullable instancetype)socketFromConnectedSocketFD:(int)socketFD delegate:(nullable id)aDelegate delegateQueue:(nullable dispatch_queue_t)dq socketQueue:(nullable dispatch_queue_t)sq error:(NSError* __autoreleasing *)error { __block BOOL errorOccured = NO; + __block NSError *thisError = nil; GCDAsyncSocket *socket = [[[self class] alloc] initWithDelegate:aDelegate delegateQueue:dq socketQueue:sq]; @@ -1093,8 +1094,7 @@ + (nullable instancetype)socketFromConnectedSocketFD:(int)socketFD delegate:(nul NSDictionary *userInfo = @{NSLocalizedDescriptionKey : errMsg}; errorOccured = YES; - if (error) - *error = [NSError errorWithDomain:GCDAsyncSocketErrorDomain code:GCDAsyncSocketOtherError userInfo:userInfo]; + thisError = [NSError errorWithDomain:GCDAsyncSocketErrorDomain code:GCDAsyncSocketOtherError userInfo:userInfo]; return; } @@ -1115,8 +1115,7 @@ + (nullable instancetype)socketFromConnectedSocketFD:(int)socketFD delegate:(nul NSDictionary *userInfo = @{NSLocalizedDescriptionKey : errMsg}; errorOccured = YES; - if (error) - *error = [NSError errorWithDomain:GCDAsyncSocketErrorDomain code:GCDAsyncSocketOtherError userInfo:userInfo]; + thisError = [NSError errorWithDomain:GCDAsyncSocketErrorDomain code:GCDAsyncSocketOtherError userInfo:userInfo]; return; } @@ -1124,6 +1123,10 @@ + (nullable instancetype)socketFromConnectedSocketFD:(int)socketFD delegate:(nul [socket didConnect:socket->stateIndex]; }}); + if (error && thisError) { + *error = thisError; + } + return errorOccured? nil: socket; }