下面的代码有什么问题?我使用 AsyncSocket 连接到 SOCKS 代理并在onSocketWillConnect
委托方法上设置代理设置。如果我省略对的调用,CFReadStreamSetProperty
套接字CFWriteStreamSetProperty
连接将顺利进行。否则,我在没有可跟踪堆栈跟踪的已释放实例上得到 [Not A Type retain](它可能与 CFNetwork 相关?)。有谁知道什么给了?
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);