Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Broken pipe when socket is closed

Tags:

c++

linux

sockets

I have a server/client app on a Linux box. If the server is not up when the client attempts to send a request, I get a SIGPIPE and the application terminates.

How can I check if the server is available on the socket before I try to write?

Also of note, I do not want to trap the SIGPIPE because the client is really part of a shared object that is used by many applications that may or may not already define their own signal handling methods.

Thanks

like image 789
steveo225 Avatar asked Mar 21 '11 20:03

steveo225


1 Answers

Pass MSG_NOSIGNAL as flags to send()

like image 136
Erik Avatar answered Sep 29 '22 23:09

Erik