我正在編寫一個應用程序來打印從服務器收到的消息。我分開在不同的線程的聆聽功能:EXC_BAD_INSTRUCTION:task_thread失敗可可
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char *read;
do {
chk = (int) recv(connfd, read, 1, 0);
if(chk==-1) {
printf("Error in recv(): connfd = %d\n",connfd);
perror(err);
}
else if (chk ==0) {
[messagesView insertText:@"\nConnection closed by remote host\n"];
printf("Connection closed by remote host\n");
}
else {
if(*read == '\n') {
[messagesView insertText:@"\\n\n"];
printf("\\n");
}
else if (*read == '\r') {
[messagesView insertText:@"\\r\r"];
printf("\\r");
}
else {
[messagesView insertText:[NSString stringWithFormat:@"%c",*read]];
printf("%c", *read);
}
printf(" -- %d\n",*read);
}
} while (chk>0);
[pool drain];
chk和connfd是int,messagesView是一個NSTextView *。 當我呼叫[messagesView insertText:]
時,應用程序崩潰,並且我收到標題中的錯誤。如果我評論所有這些調用,應用程序工作正常,我可以在控制檯中閱讀正確的消息。 有什麼建議嗎?
您是否使用Grand Central Dispatch? – 2011-04-18 18:21:57