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.
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
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
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
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):