What's wrong with the code below? I use AsyncSocket to connect to a SOCKS proxy and set the proxy settings on onSocketWillConnect
delegate method. If I omit the calls to CFReadStreamSetProperty
and CFWriteStreamSetProperty
the socket connection will follow through smoothly. Else, I get a [Not A Type retain] on a deallocated instance with no traceable stack trace (It might be CFNetwork related?). Does anyone have any idea what gives?
CFDictionaryRef proxyDict = CFNetworkCopySystemProxySettings();
CFMutableDictionaryRef socksConfig = CFDictionaryCreateMutableCopy(NULL, 0, proxyDict);
CFDictionarySetValue(socksConfig, kCFStreamPropertySOCKSProxyHost, CFSTR("192.168.1.148"));
CFDictionarySetValue(socksConfig, kCFStreamPropertySOCKSProxyPort, (__bridge CFNumberRef)[NSNumber numberWithInt:3129]);
CFDictionarySetValue(socksConfig, kCFStreamPropertySOCKSVersion, kCFStreamSocketSOCKSVersion4);
// set SOCKS for read streams
CFReadStreamRef readStream = [sock getCFReadStream];
if (!CFReadStreamSetProperty(readStream, kCFStreamPropertySOCKSProxy, socksConfig)) {
CFStreamError error = CFReadStreamGetError(readStream);
NSLog(@"[SEVERE] Web Socket Read Stream Error: %ld[%ld]", error.domain, error.error);
}
// set SOCKS for write stream
CFWriteStreamRef writeStream = [sock getCFWriteStream];
if (!CFWriteStreamSetProperty(writeStream, kCFStreamPropertySOCKSProxy, socksConfig)) {
CFStreamError error = CFWriteStreamGetError(writeStream);
NSLog(@"[SEVERE] Web Socket Write Stream Error: %ld[%ld]", error.domain, error.error);
}
// Release
CFRelease(socksConfig);
CFRelease(proxyDict);
CFReadStreamSetProperty
? – Garceau