发布/临时构建失败但在调试模式下工作(ios)

发布于 2024-12-20 16:57:01 字数 3146 浏览 3 评论 0原文

使用 TCP 套接字在后台模式(ios)运行示例应用程序。当客户端发送任何消息并等待另一条消息时,它会给出消息(本地通知)。当应用程序在调试中运行时它工作正常,但在 10 年后在发布模式下崩溃秒。 使用:xcode 4.2 & iPad 2 用于测试..

这是我正在使用的代码:

 struct sockaddr_in serv_addr, cli_addr;

 CFReadStreamRef hReadStream;

 sockfd = socket(AF_INET, SOCK_STREAM, 0);
 if (sockfd < 0) printf("Sockfd Error\n");

 bzero((char *) &serv_addr, sizeof(serv_addr));
 portNo = 3600;//atoi(argv);
 serv_addr.sin_family = AF_INET;
 serv_addr.sin_addr.s_addr = INADDR_ANY;
 serv_addr.sin_port = htons(portNo);
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
   sizeof(serv_addr)) < 0) 
 printf("bind error\n");



listen(sockfd,5); 

clilen = sizeof(cli_addr);

newsockfd = 1;


while(newsockfd)
{  

    newsockfd = accept(sockfd, 
                       (struct sockaddr *) &cli_addr, 
                       &clilen);
    NSLog(@"newsockfd create %d\n",newsockfd);

    remoteAdd = inet_ntoa(cli_addr.sin_addr);

    //cout << remoteAdd << " port =  "  << cli_addr.sin_port << endl;

    portNo = cli_addr.sin_port;

    #if defined(__IPHONE_4_0) && !(TARGET_IPHONE_SIMULATOR)

        NSLog(@"newsocket %d\n",newsockfd);

        // Only do this if it is a SipSocket we are watching
        if (newsockfd)
        {
            // Set it to non-blocking
            //int set = 0;
            //ioctl(newsockfd, FIONBIO, reinterpret_cast<int>(&set));

            CFStreamCreatePairWithSocket (kCFAllocatorDefault, newsockfd,
                                          &hReadStream, NULL);
            if (CFReadStreamSetProperty(hReadStream,
                                        kCFStreamNetworkServiceType,
                                        kCFStreamNetworkServiceTypeVoIP) != TRUE)
            {
                // An error occured, delete the stream
                if(hReadStream != NULL)
                {
                    CFReadStreamClose(hReadStream);
                    CFRelease(hReadStream);
                    hReadStream = NULL;
                }

                //return -1;
            }
            else NSLog(@" >>>>>>>>>>>>>>>>>>> property set Here <<<<<<<<<<<<<<<<\n");

            if (CFReadStreamOpen(hReadStream) != TRUE)
            {
                // An error occured, delete the stream
                if(hReadStream != NULL)
                {
                    CFReadStreamClose(hReadStream);
                    CFRelease(hReadStream);
                    hReadStream = NULL;
                }

                // return -1;
            }
            else NSLog(@"read....\n");
        }
    #endif      

    [self test];
}

设备日志中的崩溃报告:

"Application 'Demo' exited abnormally with signal 9: Killed: 9" &
"unknown ReportCrash[10915] <Error>: Saved crashreport to
/var/mobile/Library/Logs/CrashReporter/servertest_2011-12-13-163920_EyeBalls-iPad.plist
using uid: 0 gid: 0, synthetic_euid: 501 egid: 0"

尝试找到错误,但在调试模式下工作正常在设备日志或调试窗口中完全没有发现错误..请帮助我: (

Running a sample application in background mode(ios) using TCP sockets.It give message(a local notification ) when client send any message and wait for another message.It works fine when the application run in debugging, but crashes in release mode after 10 seconds.
used: xcode 4.2 & iPad 2 for testing..

This is the code I'm working with:

 struct sockaddr_in serv_addr, cli_addr;

 CFReadStreamRef hReadStream;

 sockfd = socket(AF_INET, SOCK_STREAM, 0);
 if (sockfd < 0) printf("Sockfd Error\n");

 bzero((char *) &serv_addr, sizeof(serv_addr));
 portNo = 3600;//atoi(argv);
 serv_addr.sin_family = AF_INET;
 serv_addr.sin_addr.s_addr = INADDR_ANY;
 serv_addr.sin_port = htons(portNo);
 if (bind(sockfd, (struct sockaddr *) &serv_addr,
   sizeof(serv_addr)) < 0) 
 printf("bind error\n");



listen(sockfd,5); 

clilen = sizeof(cli_addr);

newsockfd = 1;


while(newsockfd)
{  

    newsockfd = accept(sockfd, 
                       (struct sockaddr *) &cli_addr, 
                       &clilen);
    NSLog(@"newsockfd create %d\n",newsockfd);

    remoteAdd = inet_ntoa(cli_addr.sin_addr);

    //cout << remoteAdd << " port =  "  << cli_addr.sin_port << endl;

    portNo = cli_addr.sin_port;

    #if defined(__IPHONE_4_0) && !(TARGET_IPHONE_SIMULATOR)

        NSLog(@"newsocket %d\n",newsockfd);

        // Only do this if it is a SipSocket we are watching
        if (newsockfd)
        {
            // Set it to non-blocking
            //int set = 0;
            //ioctl(newsockfd, FIONBIO, reinterpret_cast<int>(&set));

            CFStreamCreatePairWithSocket (kCFAllocatorDefault, newsockfd,
                                          &hReadStream, NULL);
            if (CFReadStreamSetProperty(hReadStream,
                                        kCFStreamNetworkServiceType,
                                        kCFStreamNetworkServiceTypeVoIP) != TRUE)
            {
                // An error occured, delete the stream
                if(hReadStream != NULL)
                {
                    CFReadStreamClose(hReadStream);
                    CFRelease(hReadStream);
                    hReadStream = NULL;
                }

                //return -1;
            }
            else NSLog(@" >>>>>>>>>>>>>>>>>>> property set Here <<<<<<<<<<<<<<<<\n");

            if (CFReadStreamOpen(hReadStream) != TRUE)
            {
                // An error occured, delete the stream
                if(hReadStream != NULL)
                {
                    CFReadStreamClose(hReadStream);
                    CFRelease(hReadStream);
                    hReadStream = NULL;
                }

                // return -1;
            }
            else NSLog(@"read....\n");
        }
    #endif      

    [self test];
}

Crash report in device log :

"Application 'Demo' exited abnormally with signal 9: Killed: 9" &
"unknown ReportCrash[10915] <Error>: Saved crashreport to
/var/mobile/Library/Logs/CrashReporter/servertest_2011-12-13-163920_EyeBalls-iPad.plist
using uid: 0 gid: 0, synthetic_euid: 501 egid: 0"

Trying to found the bug but it works fine in debug mode Exactly no error found in device log or debug window..Please help me :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终陌 2024-12-27 16:57:01

您可以将编译器选项切换为 llvm gcc4.2 。我猜这个问题与 clang 有关。
希望它能正常工作。

you can switch your compiler option to llvm gcc4.2 . I guess it issue related to clang.
hope it will work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文