18

I am trying to use SO_NOSIGPIPE in a tcp socket.

  int set = 1;
  setsockopt(sockDesc, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int);

but an error is coming:

   error: SO_NOSIGPIPE was not declared in this scope

Is there any header files required, to use that. I have searched over the Internet but didn't get any useful solution.

JonasVautherin
  • 7,297
  • 6
  • 49
  • 95
Ankur
  • 330
  • 2
  • 8
  • 17
  • 1
    possible duplicate of [How to prevent SIGPIPEs (or handle them properly)](http://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly) – Klas Lindbäck Nov 05 '14 at 08:35
  • 1
    It's not a standard option, you need to find another way yo handle (or ignore) the signal. For a list of all standard options, see e.g. [this reference](http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_10_16). – Some programmer dude Nov 05 '14 at 08:36
  • Maybe this does help you? http://stackoverflow.com/q/17682349/2003898 – dhein Nov 05 '14 at 08:38

1 Answers1

27

There is no SO_NOSIGPIPE in Linux (nor some other systems). You can instead use the MSG_NOSIGNAL flag when calling send(), or use signal(SIGPIPE, SIG_IGN) to make your entire application ignore SIGPIPE.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436