@@ -423,10 +423,16 @@ MockServer::MockServer(int family, unsigned short port)
423423 // Send TCP data right away.
424424 setsockopt (tcpfd_, IPPROTO_TCP, TCP_NODELAY,
425425 BYTE_CAST &optval , sizeof (int ));
426+ #if defined(SO_NOSIGPIPE)
427+ setsockopt (tcpfd_, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, sizeof (optval));
428+ #endif
426429
427430 // Create a UDP socket to receive data on.
428431 udpfd_ = socket (family, SOCK_DGRAM, 0 );
429432 EXPECT_NE (ARES_SOCKET_BAD, udpfd_);
433+ #if defined(SO_NOSIGPIPE)
434+ setsockopt (udpfd_, SOL_SOCKET, SO_NOSIGPIPE, (void *)&optval, sizeof (optval));
435+ #endif
430436
431437 // Bind the sockets to the given port.
432438 if (family == AF_INET) {
@@ -655,6 +661,7 @@ void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr,
655661
656662 /* DNS 0x20 will mix case, do case-insensitive matching of name in request */
657663 char lower_name[256 ];
664+ int flags = 0 ;
658665 arestest_strtolower (lower_name, name, sizeof (lower_name));
659666
660667 // Before processing, let gMock know the request is happening.
@@ -701,7 +708,11 @@ void MockServer::ProcessRequest(ares_socket_t fd, struct sockaddr_storage* addr,
701708 addrlen = 0 ;
702709 }
703710
704- ares_ssize_t rc = (ares_ssize_t )sendto (fd, BYTE_CAST reply.data (), (SEND_TYPE_ARG3)reply.size (), 0 ,
711+ #ifdef MSG_NOSIGNAL
712+ flags |= MSG_NOSIGNAL;
713+ #endif
714+
715+ ares_ssize_t rc = (ares_ssize_t )sendto (fd, BYTE_CAST reply.data (), (SEND_TYPE_ARG3)reply.size (), flags,
705716 (struct sockaddr *)addr, addrlen);
706717 if (rc < static_cast <ares_ssize_t >(reply.size ())) {
707718 std::cerr << " Failed to send full reply, rc=" << rc << std::endl;
0 commit comments