Add logging to IOChannel

This commit is contained in:
moyamo 2015-02-27 18:06:30 +02:00
parent 467cc80b0d
commit c06bfac0a9

View file

@ -1,8 +1,10 @@
import asyncore, socket import asyncore, socket
import logging
class IOChannel(asyncore.dispatcher): class IOChannel(asyncore.dispatcher):
def __init__(self, host, port, callback): def __init__(self, host, port, callback):
asyncore.dispatcher.__init__(self) asyncore.dispatcher.__init__(self)
self.logger = logging.getLogger(self.__class__.__name__)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port)) self.connect((host, port))
@ -12,6 +14,7 @@ class IOChannel(asyncore.dispatcher):
def sendData(self, data): def sendData(self, data):
self.buffer += data self.buffer += data
self.logger.debug("Added Data to buffer. len(buffer) == %d", len(self.buffer))
def handle_connect(self): def handle_connect(self):
pass pass
@ -26,6 +29,7 @@ class IOChannel(asyncore.dispatcher):
def handle_write(self): def handle_write(self):
sent = self.send(self.buffer) sent = self.send(self.buffer)
self.buffer = self.buffer[sent:] self.buffer = self.buffer[sent:]
self.logger.debug("Flush buffer. len(buffer) == %d", len(self.buffer))
def writable(self): def writable(self):
return (len(self.buffer) > 0) return (len(self.buffer) > 0)