I have some code that creates a pair of CFStream
objects to a remote server with SSL/TLS enabled. This code works just fine on OS X, but when run under iOS, it fails. Here's the console log:
2011-04-26 22:39:35.820 RemoteSample[92127:40b] connecting to 192.168.1.187:8099
2011-04-26 22:39:35.825 RemoteSample[92127:40b] INPUT: NSStreamEventOpenCompleted
2011-04-26 22:39:35.825 RemoteSample[92127:40b] OUTPUT: NSStreamEventOpenCompleted
2011-04-26 22:39:35.827 RemoteSample[92127:40b] INPUT: NSStreamEventErrorOccurred
2011-04-26 22:39:35.828 RemoteSample[92127:40b] Error on input stream: The operation couldn’t be completed. (OSStatus error -108.)
2011-04-26 22:39:35.829 RemoteSample[92127:40b] OUTPUT: NSStreamEventErrorOccurred
2011-04-26 22:39:35.829 RemoteSample[92127:40b] Error on output stream: The operation couldn’t be completed. (OSStatus error -108.)
OSStatus error -108 appears to be memFullErr, which is simply bizarre and I'm not quite sure what to do about it. This occurs both in the simulator and on device. It compiles and runs without this issue in a Mac OS X application. Only when built for iOS does this error occur.
Having spent several hours trying various ideas and lots of searching, I could use some advice about next steps.
Here is the code:
CFReadStreamRef inCfStream = NULL;
CFWriteStreamRef outCfStream = NULL;
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)host, port, &inCfStream, &outCfStream);
if (inCfStream && outCfStream)
{
CFReadStreamSetProperty(inCfStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
inStream = NSMakeCollectable(inCfStream);
outStream = NSMakeCollectable(outCfStream);
[inStream setDelegate:self];
[outStream setDelegate:self];
[inStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[outStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[inStream setProperty:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], kCFStreamSSLAllowsExpiredCertificates,
[NSNumber numberWithBool:YES], kCFS开发者_如何学GotreamSSLAllowsAnyRoot,
[NSNumber numberWithBool:NO], kCFStreamSSLValidatesCertificateChain,
kCFNull,kCFStreamSSLPeerName,
nil];
if (CFReadStreamSetProperty(inCfStream, kCFStreamPropertySSLSettings, (CFTypeRef)properties) == FALSE)
{
NSLog(@"Failed to set SSL properties on read stream.");
}
inputBuffer = [[NSMutableData alloc] init];
[inStream open];
[outStream open];
}
精彩评论