views:

305

answers:

2

In solaris how to detect broken socket in send() call? i dont want to use signal.
i tried SO_NOSIGPIPE and MSG_NOSIGNAL but both are not available in Solaris and my program is getting killed with "broken pipe" error.

Is there any way to detect broken pipe?

Thanks!

+1  A: 

You'll have to use sigaction() to specifically ignore the SIGPIPE signal:

struct sigaction act;

act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);

...then send() will return -1 with errno set to EPIPE.

caf
Thanks. Its similar to signal() function. i dont want to use signal() or sigaction().
Adil
Well, that is your only option if you do not want to suffer `SIGPIPE` on Solaris. You can use the third parameter of `sigaction()` to save the previous disposition of the signal, and restore it after calling `send()` if you need to.
caf
OK Thanks. I understand.
Adil
MSG_NOSIGNAL was just standardized by POSIX in their latest revision so it is likely that Solaris will adopt this at some point.
mark4o
+1  A: 

I guess in Solaris you have only limited options. AFAIK, sigaction suggested by caf appears to be the best solution.

Jay