prevent SIGPIPE from being generated

v1.29
Brad House 7 months ago
parent 9dd7968306
commit a1afdb71a9
  1. 8
      src/lib/ares__socket.c
  2. 14
      test/ares-test.cc

@ -186,6 +186,14 @@ static int configure_socket(ares_socket_t s, struct server_state *server)
}
#endif
/* No need to emit SIGPIPE on socket errors */
#if defined(SO_NOSIGPIPE)
{
int opt = 1;
setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, (void *)&opt, sizeof(opt));
}
#endif
/* Set the socket's send and receive buffer sizes. */
if ((channel->socket_send_buffer_size > 0) &&
setsockopt(s, SOL_SOCKET, SO_SNDBUF,

14
test/ares-test.cc vendored

@ -431,10 +431,16 @@ MockServer::MockServer(int family, unsigned short port)
// Send TCP data right away.
setsockopt(tcpfd_, IPPROTO_TCP, TCP_NODELAY,
BYTE_CAST &optval , sizeof(int));
#if defined(SO_NOSIGPIPE)
setsockopt(tcpfd_, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, sizeof(optval));
#endif
// Create a UDP socket to receive data on.
udpfd_ = socket(family, SOCK_DGRAM, 0);
EXPECT_NE(ARES_SOCKET_BAD, udpfd_);
#if defined(SO_NOSIGPIPE)
setsockopt(udpfd_, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, sizeof(optval));
#endif
// Bind the sockets to the given port.
if (family == AF_INET) {
@ -655,6 +661,8 @@ std::set<ares_socket_t> MockServer::fds() const {
void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr,
ares_socklen_t addrlen, const std::string &reqstr,
int qid, const std::string& name, int rrtype) {
int flags = 0;
// Before processing, let gMock know the request is happening.
OnRequest(name, rrtype);
@ -695,7 +703,11 @@ void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr,
addrlen = 0;
}
ares_ssize_t rc = (ares_ssize_t)sendto(fd, BYTE_CAST reply.data(), (SEND_TYPE_ARG3)reply.size(), 0,
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
ares_ssize_t rc = (ares_ssize_t)sendto(fd, BYTE_CAST reply.data(), (SEND_TYPE_ARG3)reply.size(), flags,
(struct sockaddr *)addr, addrlen);
if (rc < static_cast<ares_ssize_t>(reply.size())) {
std::cerr << "Failed to send full reply, rc=" << rc << std::endl;

Loading…
Cancel
Save