From: Mattias Lundberg Date: Wed, 19 Mar 2014 14:01:08 +0000 (+0100) Subject: Add response time to the response when querying a server. X-Git-Tag: v1.13.0~31^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fead16cc459603cb65cf456aa22cdf6e25357671;p=thirdparty%2Fdnspython.git Add response time to the response when querying a server. --- diff --git a/dns/query.py b/dns/query.py index 29965cac..5a48e991 100644 --- a/dns/query.py +++ b/dns/query.py @@ -212,6 +212,7 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, if source is not None: s.bind(source) _wait_for_writable(s, expiration) + begin_time = time.time() s.sendto(wire, destination) while 1: _wait_for_readable(s, expiration) @@ -225,9 +226,11 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, '%s instead of %s' % (from_address, destination)) finally: + response_time = time.time() - begin_time s.close() r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac, one_rr_per_rrset=one_rr_per_rrset) + r.time = response_time if not q.is_response(r): raise BadResponse return r @@ -303,6 +306,7 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, try: expiration = _compute_expiration(timeout) s.setblocking(0) + begin_time = time.time() if source is not None: s.bind(source) _connect(s, destination) @@ -318,9 +322,11 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0, (l,) = struct.unpack("!H", ldata) wire = _net_read(s, l, expiration) finally: + response_time = time.time() - begin_time() s.close() r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac, one_rr_per_rrset=one_rr_per_rrset) + r.time = response_time if not q.is_response(r): raise BadResponse return r