Keep a track of bytes written and read per server

This commit is contained in:
jesopo 2018-11-08 13:31:05 +00:00
parent 26a16a7762
commit 6bf6905262

View file

@ -32,6 +32,8 @@ class Server(IRCObject.Object):
self.read_buffer = b"" self.read_buffer = b""
self.recent_sends = [] # type: typing.List[float] self.recent_sends = [] # type: typing.List[float]
self.cached_fileno = None # type: typing.Optional[int] self.cached_fileno = None # type: typing.Optional[int]
self.bytes_written = 0
self.bytes_read = 0
self.users = {} # type: typing.Dict[str, IRCUser.User] self.users = {} # type: typing.Dict[str, IRCUser.User]
self.new_users = set([]) #type: typing.Set[IRCUser.User] self.new_users = set([]) #type: typing.Set[IRCUser.User]
@ -236,6 +238,7 @@ class Server(IRCObject.Object):
if not data: if not data:
self.disconnect() self.disconnect()
return None return None
self.bytes_read += len(data)
data = self.read_buffer+data data = self.read_buffer+data
self.read_buffer = b"" self.read_buffer = b""
@ -294,8 +297,10 @@ class Server(IRCObject.Object):
def _send(self): def _send(self):
if not len(self.write_buffer): if not len(self.write_buffer):
self.write_buffer = self.buffered_lines.pop(0) self.write_buffer = self.buffered_lines.pop(0)
self.write_buffer = self.write_buffer[self.socket.send(
self.write_buffer):] bytes_written = self.socket.send(self.write_buffer)
self.bytes_written += bytes_written
self.write_buffer = self.write_buffer[bytes_written:]
now = time.monotonic() now = time.monotonic()
self.recent_sends.append(now) self.recent_sends.append(now)