How to catch sigpipe in iphone application?

How can I catch sigpipe in iphone / objective-c?

thanks

+3
source share
5 answers

One important fact for testing SigPipeHandler:

For me, this did not work when the debugger was attacked. Therefore, when starting the application directly from Xcode, the handler is not called. Meanwhile, on a device without a debugger attached, the handler is working properly.

+4
source

Use old good POSIX code:

#include <signal.h>

void SigPipeHandler(int s);

void SigPipeHandler(int s)
{
    // do your handling
}

Initiate anywhere (main.m?) With

signal(SIGPIPE, SigPipeHandler);
+3
source

SO_NOSIGPIPE, : SIGPIPE ( )

+1

The first answer does not work. I am also trying to use the solution described in the second post link:

int main(int argc, char *argv[ ]) {
   struct sigaction mySigAction;
   mySigAction.sa_handler = SIG_IGN;
   sigemptyset(&mySigAction.sa_mask);
   sigaction(SIGPIPE, &mySigAction, NULL);
   ...
}

but this code doesn't work either. Does anyone know a solution to this problem?

+1
source

The first answer works fine. but you have to put everything in a file main.mm.

And in static class(Singleton)he also works.

#import <UIKit/UIKit.h>
#import <sys/signal.h>
#if TARGET_IPHONE_SIMULATOR
#endif

void SigPipeHandler(int s)
{
    NSLog(@"We Got a Pipe Single :%d____________",s);
}

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    signal(SIGPIPE, SigPipeHandler);
    int retVal = UIApplicationMain(argc, argv, nil, @"FullAppDelegate");
    [pool release];
    return retVal;
}
+1
source

Source: https://habr.com/ru/post/1715434/


All Articles