Skip to content

Commit

Permalink
THRIFT-5456 Disable SIGPIPE on TSocketServer
Browse files Browse the repository at this point in the history
CLient: cpp
Patch: Kevin Wojniak

This closes apache#2440
  • Loading branch information
kainjow authored and Jens-G committed Oct 21, 2021
1 parent 0f76053 commit 839a1da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/cpp/src/thrift/transport/TNonblockingServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ void TNonblockingServerSocket::_setup_sockopts() {
errno_copy);
}

#ifdef SO_NOSIGPIPE
if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TNonblockingServerSocket::listen() setsockopt() SO_NOSIGPIPE", errno_copy);
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not set SO_NOSIGPIPE",
errno_copy);
}
#endif

// Set NONBLOCK on the accept socket
int flags = THRIFT_FCNTL(serverSocket_, THRIFT_F_GETFL, 0);
if (flags == -1) {
Expand Down
11 changes: 11 additions & 0 deletions lib/cpp/src/thrift/transport/TServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ void TServerSocket::_setup_sockopts() {
throw TTransportException(TTransportException::NOT_OPEN, "Could not set SO_LINGER", errno_copy);
}

#ifdef SO_NOSIGPIPE
if (-1 == setsockopt(serverSocket_, SOL_SOCKET, SO_NOSIGPIPE, &one, sizeof(one))) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
GlobalOutput.perror("TServerSocket::listen() setsockopt() SO_NOSIGPIPE", errno_copy);
close();
throw TTransportException(TTransportException::NOT_OPEN,
"Could not set SO_NOSIGPIPE",
errno_copy);
}
#endif

// Set NONBLOCK on the accept socket
int flags = THRIFT_FCNTL(serverSocket_, THRIFT_F_GETFL, 0);
if (flags == -1) {
Expand Down

0 comments on commit 839a1da

Please sign in to comment.