Benches Uncategorized

1

Ignore SIGPIPE signal

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

My application trying to connect to server and receive signal SIGPIPE. How can i catch this signal?

I found two solution for this problem, but either doesn't work.

First solution is:

void SigPipeHandler(int s);
int main(int argc, char *argv[]) {
signal(SIGPIPE, SigPipeHandler);
...
}
void SigPipeHandler(int s){
NSLog(@"SigPipeHandler");
}

In second solution I'm trying to ignore SIGPIPE signal as follow:


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

but signal isn't ignored. I'm also trying to handle signal to set handler:


int main(int argc, char *argv[]){
struct sigaction mySigAction;
mySigAction.sa_sigaction = SignalHandler;
mySigAction.sa_flags = SA_SIGINFO;
sigemptyset(&mySigAction.sa_mask);
sigaction(SIGPIPE, &mySigAction, NULL);
...
}
void SignalHandler(int sig, siginfo_t *info, void *context){
NSLog(@"in SignalHandler");
}

but it doesn't work too.

And on the whole, why can I handle any signal?

Message was edited by: iruirc

Message was edited by: iruirc

1 reply

Sign in or join Beachball Help to reply.

  1. 0

    etresoft

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    What kind of application is this? Cocoa? Carbon? Are you using threads? How do you know you are getting SIGPIPE?

    Handling signals can be very complicated in a modern MacOS X program. Normally you shouldn't even need them.Have you tried the "bsd_signal" wrapper?