diff --git a/Ports/iOSPort/nativeSources/SocketImpl.m b/Ports/iOSPort/nativeSources/SocketImpl.m index 3c2fecef1a..622c24a8fa 100644 --- a/Ports/iOSPort/nativeSources/SocketImpl.m +++ b/Ports/iOSPort/nativeSources/SocketImpl.m @@ -46,19 +46,23 @@ -(BOOL)connect:(NSString*)host port:(int)port timeout:(int)timeout{ }); } - [inputStream open]; - [outputStream open]; - while ([outputStream streamStatus] == NSStreamStatusOpening) { + if (inputStream != nil) { + [inputStream open]; + } + if (outputStream != nil) { + [outputStream open]; + } + while (outputStream != nil && [outputStream streamStatus] == NSStreamStatusOpening) { _yield(); usleep(100000); _resume(); } - while ([inputStream streamStatus] == NSStreamStatusOpening) { + while (inputStream != nil && [inputStream streamStatus] == NSStreamStatusOpening) { _yield(); usleep(100000); _resume(); } - if ([self isInputShutdown] || [self isOutputShutdown]) { + if (outputStream == nil || inputStream == nil || [self isInputShutdown] || [self isOutputShutdown]) { connected = NO; } else { connected = YES;