用ios6模拟器打破CFStreamCreatePairWithSocketToHost?

用ios6模拟器打破CFStreamCreatePairWithSocketToHost?,第1张

概述我注意到在我的程序中使用CFStreamCreatePairWithSocketToHost时出现了随机的EXC_BADACCESS错误,但只有ios6 – 当使用ios5模拟器时(甚至在带有 xcode4.5的ios6sdk内部)一切正常.我最终将问题提取到一个小的测试程序中 – 如果你启用了guard malloc,它会立即爆炸(见下面的崩溃).这也发生在弧形和非弧形的情况下. @interf 我注意到在我的程序中使用CFStreamCreatePairWithSocketToHost时出现了随机的EXC_BADACCESS错误,但只有ios6 – 当使用ios5模拟器时(甚至在带有 xcode4.5的ios6sdk内部)一切正常.我最终将问题提取到一个小的测试程序中 – 如果你启用了guard malloc,它会立即爆炸(见下面的崩溃).这也发生在弧形和非弧形的情况下.
@interface PHAppDelegate : UIResponder <UIApplicationDelegate,NsstreamDelegate>{    NSOutputStream*     mOutputStream;    NSinputStream*      minputStream;}@implementation PHAppDelegate- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    Nsstring* testAddress = @"192.168.1.0";    [self openWithHost:testAddress port:444];    return YES;}- (voID)openWithHost:(Nsstring*)host port:(int)port{    CFReadStreamRef readStream;    CFWriteStreamRef writeStream;    CFStreamCreatePairWithSocketToHost(kcfAllocatorDefault,(CFStringRef)host,/*ip_addr*/                                       port,&readStream,&writeStream);    minputStream = (NSinputStream *)readStream;    mOutputStream = (NSOutputStream *)writeStream;    if (minputStream == nil)    {        NSLog(@"Couldn't create the inputStream using CFStreamCreatePairWithSocketsToHost()");        return;    }    if (mOutputStream == nil)    {        NSLog(@"Couldn't create the outputstream using CFStreamCreatePairWithSocketsToHost()");        return;    }    [minputStream setDelegate:self];    [mOutputStream setDelegate:self];    [minputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];    [mOutputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];    [minputStream open];    [mOutputStream open];}#pragma mark Nsstream delegate methods- (voID)stream:(Nsstream *)aStream handleEvent:(NsstreamEvent)eventCode{    NSLog(@"stream-handleEvent");}@end

在com.apple.networking.connection线程中崩溃:

#0  0x04b35140 in tcp_connection_destination_prepare_complete ()#1  0x04b34fee in tcp_connection_destination_start ()#2  0x04b34c2b in tcp_connection_start_next_destination ()#3  0x04b33c70 in tcp_connection_handle_reachability_changed ()#4  0x04b30a95 in __tcp_connection_start_block_invoke_0 ()#5  0x049fa53f in _dispatch_call_block_and_release ()#6  0x04a0c014 in _dispatch_clIEnt_callout ()#7  0x049fc418 in _dispatch_queue_drain ()#8  0x049fc2a6 in _dispatch_queue_invoke ()#9  0x049fd280 in _dispatch_root_queue_drain ()#10 0x049fd450 in _dispatch_worker_thread2 ()#11 0x94e7de12 in _pthread_wqthread ()#12 0x94e65cca in start_wqthread ()EXC_BADACCESS @ address 0x04b351400x04b3513b  <+0072>  call   0x4b332de <tcp_connection_destination_List_remove>0x04b35140  <+0077>  mov    0x28(%esi),%eax0x04b35143  <+0080>  test   %eax,%eax
解决方法 我有非常相似的代码,适用于iOS 5.x和iOS 6.x.唯一的区别是我在调用CFStreamCreatePairWithSocketToHost之前将CFReadStreamRef和CFWriteStreamRef初始化为NulL,并为分配器传递NulL.为方便起见,我通常还会在Nsstream上将代码添加为类别.所以,代码看起来像这样:
+ (voID)createStreamsToHostnamed:(Nsstring*)hostname port:(NSInteger)port inputStream:(NSinputStream* __autoreleasing *)inputStream outputStream:(NSOutputStream* __autoreleasing *)outputStream {    CFReadStreamRef readStream = NulL;    CFWriteStreamRef writeStream = NulL;    // Create a pair of of streams for a socket to the host specifIEd    CFStreamCreatePairWithSocketToHost(NulL,(__brIDge CFStringRef)hostname,port,&writeStream);    // Assign the output parameters    *inputStream  = (__brIDge_transfer NSinputStream*)readStream;    *outputStream = (__brIDge_transfer NSOutputStream*)writeStream;}

您可以使用以下代码调用该方法:

@interface SomeClass : NSObject <NsstreamDelegate>@end@implementation SomeClass {    NSinputStream* _inputStream;    NSOutputStream* _outputStream;}- (voID)_setupMethod {    __autoreleasing NSinputStream* autoreleasinginputStream = nil;    __autoreleasing NSOutputStream* autoreleasingOutputStream = nil;    [Nsstream createStreamsToHostnamed:kHostConstant port:kPortConstant inputStream:&autoreleasinginputStream outputStream:&autoreleasingOutputStream];    if(autoreleasinginputStream != nil && autoreleasingOutputStream != nil) {        _inputStream = autoreleasinginputStream;        [_inputStream setDelegate:self];        [_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];        _outputStream = autoreleasingOutputStream;        [_outputStream setDelegate:self];        [_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];        [_inputStream open];        [_outputStream open];    }}// NsstreamDelegate methods ...@end
总结

以上是内存溢出为你收集整理的用ios6模拟器打破CFStreamCreatePairWithSocketToHost?全部内容,希望文章能够帮你解决用ios6模拟器打破CFStreamCreatePairWithSocketToHost?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1104798.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存