[svn] commit: r182 - /branches/f2f200910/src/bin/host/host.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Oct 29 22:04:22 UTC 2009
Author: jreed
Date: Thu Oct 29 22:04:22 2009
New Revision: 182
Log:
Add elapsed time when verbose (which is my default for now).
Update usage statement.
Modified:
branches/f2f200910/src/bin/host/host.cc
Modified: branches/f2f200910/src/bin/host/host.cc
==============================================================================
--- branches/f2f200910/src/bin/host/host.cc (original)
+++ branches/f2f200910/src/bin/host/host.cc Thu Oct 29 22:04:22 2009
@@ -15,6 +15,7 @@
char* server = "127.0.0.1";
int verbose = 1; // later make this an option and default to 0
int first_time = 1;
+struct timeval before_time, after_time;
int
host_lookup(char* name, char* type)
@@ -65,6 +66,10 @@
return (1);
}
+ if (verbose) {
+ gettimeofday(&before_time, NULL);
+ }
+
msg.getBuffer().sendTo(s, *res->ai_addr, res->ai_addrlen);
Message rmsg;
@@ -77,6 +82,11 @@
if (rmsg.getBuffer().recvFrom(s, sa, &sa_len) > 0) {
try {
rmsg.fromWire();
+
+ if (verbose) {
+ gettimeofday(&after_time, NULL);
+ }
+
// HEADER and QUESTION SECTION:
std::cout << rmsg.toText() << std::endl;
// ;; ANSWER SECTION:
@@ -84,9 +94,18 @@
// SECTION_AUTHORITY
// SECTION_ADDITIONAL
+ if (before_time.tv_usec > after_time.tv_usec) {
+ after_time.tv_usec += 1000000;
+ --after_time.tv_sec;
+ }
+
+ int elapsed_time =
+ (after_time.tv_sec - before_time.tv_sec)
+ + ((after_time.tv_usec - before_time.tv_usec))/1000;
+
std::cout << "\nReceived " <<
boost::lexical_cast<string>(rmsg.getBuffer().getSize()) <<
- " bytes\n";
+ " bytes in " << elapsed_time << " ms\n";
// TODO: " bytes from 127.0.0.1#53 in 0 ms
} catch (...) {
std::cerr << "parse failed" << std::endl;
@@ -102,7 +121,7 @@
{
if (argc < 2) {
- cout << "Usage: host _hostname_\n";
+ cout << "Usage: host hostname [server]\n";
}
else {
More information about the bind10-changes
mailing list