diff options
| author | Mattias Lundberg <lundberg.mattias@gmail.com> | 2014-03-19 15:01:08 +0100 |
|---|---|---|
| committer | Petr Viktorin <pviktori@redhat.com> | 2015-05-27 13:13:00 +0200 |
| commit | 65c9a66eaa34d84d5f334c19eca317cff2f93558 (patch) | |
| tree | cfcd97e560eddf56b4a6e37bcf8ee58ae73d76d7 /dns/query.py | |
| parent | 2eaf67ae39bb7c8b1363b16736d7054a8c0fd967 (diff) | |
| download | dnspython-65c9a66eaa34d84d5f334c19eca317cff2f93558.tar.gz | |
Add response time to the response when querying a server.
Diffstat (limited to 'dns/query.py')
| -rw-r--r-- | dns/query.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/dns/query.py b/dns/query.py index c416615..27c59d8 100644 --- a/dns/query.py +++ b/dns/query.py @@ -210,6 +210,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) @@ -223,9 +224,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 @@ -301,6 +304,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) @@ -316,9 +320,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 |
