Browse Source

[2003] added get_total_len() DNSTCPSendBuffer and use it for better log msg.

JINMEI Tatuya 13 years ago
parent
commit
85fcef3452

+ 9 - 2
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

+ 2 - 2
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

+ 5 - 0
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):