set SO_NOSIGPIPE socket option when available

This ensures we avoid SIGPIPE on socket disconnect on Darwin.
This commit is contained in:
Joel Dice 2013-03-18 11:43:00 -06:00
parent a648787e11
commit d873f096a1

View File

@ -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<char*>(&opt), sizeof(int));
if (r != 0) {
throwIOException(e);
return;
{ int opt = 1;
int r = ::setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
reinterpret_cast<char*>(&opt), sizeof(int));
if (r != 0) {
throwIOException(e);
return;
}
}
r = ::bind(s, reinterpret_cast<sockaddr*>(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<char*>(&opt), sizeof(int));
if (r != 0) {
throwIOException(e);
return;
}
}
#endif
{ int r = ::bind
(s, reinterpret_cast<sockaddr*>(address), sizeof(sockaddr_in));
if (r != 0) {
throwIOException(e);
return;
}
}
}