gpt4 book ai didi

objective-c - 设置 SOCKS 代理配置后 CFStream 崩溃

转载 作者:可可西里 更新时间:2023-11-01 03:34:40 26 4
gpt4 key购买 nike

下面的代码有什么问题?我使用 AsyncSocket 连接到 SOCKS 代理并在 onSocketWillConnect 委托(delegate)方法上设置代理设置。如果我省略对 CFReadStreamSetPropertyCFWriteStreamSetProperty 的调用,套接字连接将顺利完成。否则,我在没有可跟踪堆栈跟踪的已释放实例上得到 [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);

最佳答案

来自 CFReadStream 的文档:

Properties that can be set configure the behavior of the stream and may be modifiable only at particular times, such as before the stream has been opened. (In fact, you should assume that you can set properties only before opening the stream, unless otherwise noted.)

onSocketWillConnect 可能来不及设置这些属性。

关于objective-c - 设置 SOCKS 代理配置后 CFStream 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12070493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com