]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2003] added get_total_len() DNSTCPSendBuffer and use it for better log msg.
authorJINMEI Tatuya <jinmei@isc.org>
Fri, 8 Jun 2012 21:04:15 +0000 (14:04 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Fri, 8 Jun 2012 21:04:15 +0000 (14:04 -0700)
src/lib/python/isc/server_common/dns_tcp.py
src/lib/python/isc/server_common/server_common_messages.mes
src/lib/python/isc/server_common/tests/dns_tcp_test.py

index 270d11c55d284c6d4ee6eabd60aedd5f9d4071ba..3b78d0d698efe95dad245fdd90e140a17bfb52da 100644 (file)
@@ -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
index c0fc83f52bb587cd57b5ace4ba5a9fe355d5e476..bd4e3ccec4a99c0e365cb746319da43be91aa5d7 100644 (file)
@@ -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
index e5306b6b291fdf4eb9c79be2a98b0d89ed01c0c5..c46906b9bc9f6fb256561140123f4cc314a9b8a8 100644 (file)
@@ -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):