From: JINMEI Tatuya Date: Fri, 8 Jun 2012 21:04:15 +0000 (-0700) Subject: [2003] added get_total_len() DNSTCPSendBuffer and use it for better log msg. X-Git-Tag: trac2351_base~226^2~59^2~1^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=85fcef34522d4b51557583680a168372da7193f7;p=thirdparty%2Fkea.git [2003] added get_total_len() DNSTCPSendBuffer and use it for better log msg. --- diff --git a/src/lib/python/isc/server_common/dns_tcp.py b/src/lib/python/isc/server_common/dns_tcp.py index 270d11c55d..3b78d0d698 100644 --- a/src/lib/python/isc/server_common/dns_tcp.py +++ b/src/lib/python/isc/server_common/dns_tcp.py @@ -74,6 +74,12 @@ class DNSTCPSendBuffer: self.__lenbuf = struct.pack('H', socket.htons(self.__data_size)) self.__databuf = data + def get_total_len(self): + '''Return the total length of the buffer, including the length field. + + ''' + return self.__data_size + self.__len_size + def get_data(self, pos): '''Return a portion of data from a specified position. @@ -235,15 +241,16 @@ class DNSTCPContext: try: cc = self.__sock.send(data) except socket.error as ex: + total_len = self.__send_buffer.get_total_len() if ex.errno == errno.EAGAIN: logger.debug(logger.DBGLVL_TRACE_DETAIL, PYSERVER_COMMON_DNS_TCP_SEND_PENDING, ClientFormatter(self.__remote_addr), - self.__send_marker) + self.__send_marker, total_len) return self.SENDING logger.warn(PYSERVER_COMMON_DNS_TCP_SEND_ERROR, ClientFormatter(self.__remote_addr), - self.__send_marker, ex) + self.__send_marker, total_len, ex) self.__sock.close() self.__sock = None return self.CLOSED diff --git a/src/lib/python/isc/server_common/server_common_messages.mes b/src/lib/python/isc/server_common/server_common_messages.mes index c0fc83f52b..bd4e3ccec4 100644 --- a/src/lib/python/isc/server_common/server_common_messages.mes +++ b/src/lib/python/isc/server_common/server_common_messages.mes @@ -27,7 +27,7 @@ transmitted over a TCP connection, possibly after multiple send operations. The destination address and the total size of the message (including the 2-byte length field) are shown in the log message. -% PYSERVER_COMMON_DNS_TCP_SEND_ERROR failed to send TCP message to %1 (%2 bytes sent): %3 +% PYSERVER_COMMON_DNS_TCP_SEND_ERROR failed to send TCP message to %1 (%2/%3 bytes sent): %4 A DNS message has been attempted to be sent out over a TCP connection, but it failed due to some network error. Although it's not expected to happen too often, it can still happen for various reasons. The @@ -37,7 +37,7 @@ be taken at the server side. When this message is logged, the corresponding TCP connection was closed immediately after the error was detected. -% PYSERVER_COMMON_DNS_TCP_SEND_PENDING sent part TCP message to %1 (up to %2 bytes) +% PYSERVER_COMMON_DNS_TCP_SEND_PENDING sent part TCP message to %1 (up to %2/%3 bytes) Debug message. A part of DNS message has been transmitted over a TCP connection, and it's suspended because further attempt would block. The destination address and the total size of the message that has diff --git a/src/lib/python/isc/server_common/tests/dns_tcp_test.py b/src/lib/python/isc/server_common/tests/dns_tcp_test.py index e5306b6b29..c46906b9bc 100644 --- a/src/lib/python/isc/server_common/tests/dns_tcp_test.py +++ b/src/lib/python/isc/server_common/tests/dns_tcp_test.py @@ -78,6 +78,11 @@ class BufferTest(unittest.TestCase): self.check_length_field(buf, 0) self.assertEqual(None, buf.get_data(2)) + def test_get_total_len(self): + self.assertEqual(14, DNSTCPSendBuffer(b'x' * 12).get_total_len()) + self.assertEqual(2, DNSTCPSendBuffer(b'').get_total_len()) + self.assertEqual(65537, DNSTCPSendBuffer(b'X' * 65535).get_total_len()) + class FakeSocket: '''Emulating python socket w/o involving IO while allowing inspection.''' def __init__(self, proto=socket.IPPROTO_TCP):