From d873f096a1c2eb23204f3298c03122bf32a3475b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 18 Mar 2013 11:43:00 -0600 Subject: [PATCH] set SO_NOSIGPIPE socket option when available This ensures we avoid SIGPIPE on socket disconnect on Darwin. --- classpath/java-nio.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/classpath/java-nio.cpp b/classpath/java-nio.cpp index dc15639dc7..5324c7b444 100644 --- a/classpath/java-nio.cpp +++ b/classpath/java-nio.cpp @@ -262,18 +262,32 @@ setTcpNoDelay(JNIEnv* e, int d, bool on) void doBind(JNIEnv* e, int s, sockaddr_in* address) { - int opt = 1; - int r = ::setsockopt(s, SOL_SOCKET, SO_REUSEADDR, - reinterpret_cast(&opt), sizeof(int)); - if (r != 0) { - throwIOException(e); - return; + { int opt = 1; + int r = ::setsockopt(s, SOL_SOCKET, SO_REUSEADDR, + reinterpret_cast(&opt), sizeof(int)); + if (r != 0) { + throwIOException(e); + return; + } } - r = ::bind(s, reinterpret_cast(address), sizeof(sockaddr_in)); - if (r != 0) { - throwIOException(e); - return; +#ifdef SO_NOSIGPIPE + { int opt = 1; + int r = ::setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, + reinterpret_cast(&opt), sizeof(int)); + if (r != 0) { + throwIOException(e); + return; + } + } +#endif + + { int r = ::bind + (s, reinterpret_cast(address), sizeof(sockaddr_in)); + if (r != 0) { + throwIOException(e); + return; + } } }