views:

564

answers:

3

Hi,

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

thanks

+1  A: 

Use old good POSIX code:

#include <signal.h>

void SigPipeHandler(int s);

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

Init in some place (main.m?) with

signal(SIGPIPE, SigPipeHandler);
Farcaller
It doesn't work or i am don't use it right.My second thread is making this error.
donodare
Are you sure, that you install handler early enough?
Farcaller
+1  A: 

Try setting SO_NOSIGPIPE as documented here: http://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly

Simo Salminen
A: 

The first answer doesn't work. Also I'm trying to use solution described in reference of second post:

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 too. Anybody know solution of this problem?

iruirc