Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
I have developed a client/server application using socket in solaris 8.
The problem that I am facing is that the send() funtion is causing the server application to crash when client applcation is down.I googled and figured out the send() function creates SIGPIPE signal and this kills the process if the receiver application is not running.And to fix this SIGPIPE needs to supressed.

And also found that SO_NOSIGPIPE should be passed as the last parameter to the
send() to supress the signal.
But when I tried to use SO_NOSIGPIPE it is giving compilation error.I tried to include the necessary header also, but did not work.

So plz can any one help me in how to supress SIGPIPE signal.

Thanks
Dev
Posted

1 solution

How about using sigaction[^] with SIG_IGN?

I also found This[^] link from google which suggests another (better?) approach.
 
Share this answer
 
Comments
Devadutta Achary 15-Oct-12 5:53am    
Thanks Parths for your help.I went thrugh these links and learned that SO_NOSIGPIPE
can passes as a parameter to send() sigaction() to supress the SIGPIPE, but when I tried to use this in my code , it is giving compilation error .I think it not finding the correct headers for this. I am badly stuck. plz help me
parths 16-Oct-12 3:15am    
From what I learned from searching google, solaris does not support the SO_NOSIGPIPE. The article in the second link also mentions that some systems do not support SO_NOSIGPIPE. This is most probably the reason SO_NOSIGPIPE is not compiling for you.
In this scenario you can use either of the 2 approaches to
(1) ignore sigpipe altogether for your app using sigaction
(2) catch and suppress sigpipe from your send as described in the blog post linked above.
Devadutta Achary 17-Oct-12 1:57am    
Thanks Parths for your help.I tried the above approaches, but it did not solve the problem.I used signal(SIGPIPE,handler) where handler() is the function which should be called if the SIGPIPE signal is created.So but doing so,the handler() function was getting called when the SIGPIPE signal was created.But still my application is crashing, i really dont know what to write in the event handler to suppress the signal so that the application will not crash.
parths 17-Oct-12 8:36am    
What I was trying to refer to was using something like this (Note: Please don't use the code as is, make sure you check your documentation):

struct sigaction oldAction;
struct sigaction newAction;
newAction.sa_handler = SIG_IGN;
sigemptyset (&newAction.sa_mask);
newAction.sa_flags = 0;
sigaction(SIGPIPE, &newAction, &oldAction); // We can restore the old action later if we want

Also, I'd strongly suggest you revisit Kroki's blog (second link in my original answer) since that solution seems much closer to the SO_NOSIGPIPE that you were looking for.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900