|
|
|
@ -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; |
|
|
|
|