Commit 462e2807 authored by JINMEI Tatuya's avatar JINMEI Tatuya

[1697] updated the user side of MessageRenderer, either by just using the

default internal buffer or set the separate buffer by setBuffer().
parent 89f1ae8c
......@@ -307,12 +307,14 @@ makeErrorMessage(MessagePtr message, OutputBufferPtr buffer,
for_each(questions.begin(), questions.end(), QuestionInserter(message));
message->setRcode(rcode);
MessageRenderer renderer(*buffer);
MessageRenderer renderer;
renderer.setBuffer(buffer.get());
if (tsig_context.get() != NULL) {
message->toWire(renderer, *tsig_context);
} else {
message->toWire(renderer);
}
renderer.setBuffer(NULL);
LOG_DEBUG(auth_logger, DBG_AUTH_MESSAGES, AUTH_SEND_ERROR_RESPONSE)
.arg(renderer.getLength()).arg(*message);
}
......@@ -554,7 +556,8 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, MessagePtr message,
return (true);
}
MessageRenderer renderer(*buffer);
MessageRenderer renderer;
renderer.setBuffer(buffer.get());
const bool udp_buffer =
(io_message.getSocket().getProtocol() == IPPROTO_UDP);
renderer.setLengthLimit(udp_buffer ? remote_bufsize : 65535);
......@@ -563,6 +566,7 @@ AuthSrvImpl::processNormalQuery(const IOMessage& io_message, MessagePtr message,
} else {
message->toWire(renderer);
}
renderer.setBuffer(NULL);
LOG_DEBUG(auth_logger, DBG_AUTH_MESSAGES, AUTH_SEND_NORMAL_RESPONSE)
.arg(renderer.getLength()).arg(message->toText());
......@@ -683,12 +687,14 @@ AuthSrvImpl::processNotify(const IOMessage& io_message, MessagePtr message,
message->setHeaderFlag(Message::HEADERFLAG_AA);
message->setRcode(Rcode::NOERROR());
MessageRenderer renderer(*buffer);
MessageRenderer renderer;
renderer.setBuffer(buffer.get());
if (tsig_context.get() != NULL) {
message->toWire(renderer, *tsig_context);
} else {
message->toWire(renderer);
}
renderer.setBuffer(NULL);
return (true);
}
......
......@@ -154,8 +154,7 @@ createBuiltinVersionResponse(const qid_t qid, vector<uint8_t>& data) {
rrset_version_ns->addRdata(generic::NS(version_name));
message.addRRset(Message::SECTION_AUTHORITY, rrset_version_ns);
OutputBuffer obuffer(0);
MessageRenderer renderer(obuffer);
MessageRenderer renderer;
message.toWire(renderer);
data.clear();
......
......@@ -70,8 +70,7 @@ host_lookup(const char* const name, const char* const dns_class,
RRClass(dns_class),
any ? RRType::ANY() : RRType(type))); // if NULL then:
OutputBuffer obuffer(512);
MessageRenderer renderer(obuffer);
MessageRenderer renderer;
msg.toWire(renderer);
struct addrinfo hints, *res;
......@@ -111,7 +110,7 @@ host_lookup(const char* const name, const char* const dns_class,
gettimeofday(&before_time, NULL);
}
sendto(s, obuffer.getData(), obuffer.getLength(), 0, res->ai_addr,
sendto(s, renderer.getData(), renderer.getLength(), 0, res->ai_addr,
res->ai_addrlen);
struct sockaddr_storage ss;
......
......@@ -252,7 +252,8 @@ makeErrorMessage(MessagePtr message, MessagePtr answer_message,
}
for_each(questions.begin(), questions.end(), QuestionInserter(message));
message->setRcode(rcode);
MessageRenderer renderer(*buffer);
MessageRenderer renderer;
renderer.setBuffer(buffer.get());
message->toWire(renderer);
}
......@@ -303,7 +304,8 @@ public:
// Now we can clear the buffer and render the new message into it
buffer->clear();
MessageRenderer renderer(*buffer);
MessageRenderer renderer;
renderer.setBuffer(buffer.get());
ConstEDNSPtr edns(query_message->getEDNS());
const bool dnssec_ok = edns && edns->getDNSSECAwareness();
......@@ -327,6 +329,7 @@ public:
}
answer_message->toWire(renderer);
renderer.setBuffer(NULL);
LOG_DEBUG(resolver_logger, RESOLVER_DBG_DETAIL,
RESOLVER_DNS_MESSAGE_SENT)
......
......@@ -226,8 +226,10 @@ IOFetch::initIOFetch(MessagePtr& query_msg, Protocol protocol,
query_msg->setEDNS(edns_query);
}
MessageRenderer renderer; // XXX this doesn't work need to set data_->msgbuf;
MessageRenderer renderer;
renderer.setBuffer(data_->msgbuf.get());
query_msg->toWire(renderer);
renderer.setBuffer(NULL);
}
// Return protocol in use.
......
......@@ -133,10 +133,15 @@ public:
EDNSPtr msg_edns(new EDNS());
msg_edns->setUDPSize(Message::DEFAULT_MAX_EDNS0_UDPSIZE);
msg.setEDNS(msg_edns);
MessageRenderer renderer(*msgbuf_);
MessageRenderer renderer;
renderer.setBuffer(msgbuf_.get());
msg.toWire(renderer);
renderer.setBuffer(NULL);
renderer.setBuffer(expected_buffer_.get());
msg.toWire(renderer);
MessageRenderer renderer2(*expected_buffer_);
msg.toWire(renderer2);
renderer.setBuffer(NULL);
// Initialize the test data to be returned: tests will return a
// substring of this data. (It's convenient to have this as a member of
......@@ -581,20 +586,22 @@ public:
return_data_ = "Message returned to the client";
udp::endpoint remote;
socket.async_receive_from(asio::buffer(receive_buffer_, sizeof(receive_buffer_)),
remote,
boost::bind(&IOFetchTest::udpReceiveHandler, this, &remote, &socket,
_1, _2, bad_qid, second_send));
socket.async_receive_from(asio::buffer(receive_buffer_,
sizeof(receive_buffer_)),
remote,
boost::bind(&IOFetchTest::udpReceiveHandler,
this, &remote, &socket,
_1, _2, bad_qid, second_send));
service_.get_io_service().post(udp_fetch_);
if (debug_) {
cout << "udpSendReceive: async_receive_from posted, waiting for callback" <<
endl;
cout << "udpSendReceive: async_receive_from posted,"
"waiting for callback" << endl;
}
service_.run();
socket.close();
EXPECT_TRUE(run_);;
EXPECT_TRUE(run_);
}
};
......
......@@ -58,7 +58,7 @@ ConstElementPtr SQLITE_DBFILE_EXAMPLE = Element::fromJSON(
class DataSrcTest : public ::testing::Test {
protected:
DataSrcTest() : obuffer(0), renderer(obuffer), msg(Message::PARSE),
DataSrcTest() : msg(Message::PARSE),
opcodeval(Opcode::QUERY().getCode()), qid(0)
{
DataSrcPtr sql3_source = DataSrcPtr(new Sqlite3DataSrc);
......@@ -76,7 +76,6 @@ protected:
HotCache cache;
MetaDataSrc meta_source;
OutputBuffer obuffer;
MessageRenderer renderer;
Message msg;
const uint16_t opcodeval;
......
......@@ -343,7 +343,8 @@ public:
// Convert to wire format
udp_send_buffer_->clear();
MessageRenderer renderer(*udp_send_buffer_);
MessageRenderer renderer;
renderer.setBuffer(udp_send_buffer_.get());
msg.toWire(renderer);
if (mangle_response) {
......@@ -477,10 +478,9 @@ public:
setReferralExampleOrg(msg);
// Convert to wire format
// Use a temporary buffer for the dns wire data (we copy it
// Use a temporary renderer for the dns wire data (we copy it
// to the 'real' buffer below)
OutputBuffer msg_buf(BUFFER_SIZE);
MessageRenderer renderer(msg_buf);
MessageRenderer renderer;
msg.toWire(renderer);
// Expected next state (when checked) is the UDP query to example.org.
......@@ -496,12 +496,13 @@ public:
// followed by the actual data. We copy them to a new buffer
// first
tcp_send_buffer_->clear();
tcp_send_buffer_->writeUint16(msg_buf.getLength());
tcp_send_buffer_->writeData(msg_buf.getData(), msg_buf.getLength());
tcp_send_buffer_->writeUint16(renderer.getLength());
tcp_send_buffer_->writeData(renderer.getData(), renderer.getLength());
tcp_socket_.async_send(asio::buffer(tcp_send_buffer_->getData(),
tcp_send_buffer_->getLength()),
boost::bind(&RecursiveQueryTest2::tcpSendHandler, this,
tcp_send_buffer_->getLength(), _1, _2));
boost::bind(
&RecursiveQueryTest2::tcpSendHandler, this,
tcp_send_buffer_->getLength(), _1, _2));
}
/// \brief Completion Handler for Sending TCP data
......
......@@ -240,8 +240,10 @@ public:
// Convert to wire format
udp_send_buffer_->clear();
MessageRenderer renderer(*udp_send_buffer_);
MessageRenderer renderer;
renderer.setBuffer(udp_send_buffer_.get());
message.toWire(renderer);
renderer.setBuffer(NULL);
// Return a message back to the IOFetch object (after setting the
// expected length of data for the check in the send handler).
......@@ -353,8 +355,7 @@ public:
// Convert to wire format
// Use a temporary buffer for the dns wire data (we copy it
// to the 'real' buffer below)
OutputBuffer msg_buf(BUFFER_SIZE);
MessageRenderer renderer(msg_buf);
MessageRenderer renderer;
message.toWire(renderer);
// Also, take this opportunity to clear the accumulated read count in
......@@ -368,12 +369,14 @@ public:
// followed by the actual data. We copy them to a new buffer
// first
tcp_send_buffer_->clear();
tcp_send_buffer_->writeUint16(msg_buf.getLength());
tcp_send_buffer_->writeData(msg_buf.getData(), msg_buf.getLength());
tcp_send_buffer_->writeUint16(renderer.getLength());
tcp_send_buffer_->writeData(renderer.getData(), renderer.getLength());
tcp_socket_.async_send(asio::buffer(tcp_send_buffer_->getData(),
tcp_send_buffer_->getLength()),
boost::bind(&RecursiveQueryTest3::tcpSendHandler,
this, tcp_send_buffer_->getLength(), _1, _2));
boost::bind(
&RecursiveQueryTest3::tcpSendHandler,
this,
tcp_send_buffer_->getLength(), _1, _2));
}
/// \brief Completion Handler for Sending TCP data
......
......@@ -43,8 +43,6 @@ SrvTestBase::SrvTestBase() : request_message(Message::RENDER),
qclass(RRClass::IN()),
qtype(RRType::A()), io_sock(NULL),
io_message(NULL), endpoint(NULL),
request_obuffer(0),
request_renderer(request_obuffer),
response_obuffer(new OutputBuffer(0))
{}
......
......@@ -100,7 +100,6 @@ protected:
asiolink::IOSocket* io_sock;
asiolink::IOMessage* io_message;
const asiolink::IOEndpoint* endpoint;
isc::util::OutputBuffer request_obuffer;
isc::dns::MessageRenderer request_renderer;
isc::util::OutputBufferPtr response_obuffer;
std::vector<uint8_t> data;
......
......@@ -61,7 +61,8 @@ Scan::scan(const CommandOptions& options) {
RRType::A()));
OutputBufferPtr msgbuf(new OutputBuffer(512));
MessageRenderer renderer(*msgbuf);
MessageRenderer renderer;
renderer.setBuffer(msgbuf.get());
message.toWire(renderer);
iterateFlagsStart(msgbuf, options);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment