Fix bugs in OutputBuffer

This commit is contained in:
XANTRONIX Development 2024-11-27 19:09:47 -05:00
parent ee3ed2bff8
commit 97050eafe4

View file

@ -17,17 +17,25 @@ class OutputBuffer():
def write(self, data: bytes):
remaining = len(data)
offset_i = 0
while remaining > 0:
needed = self.size - self.offset
copy = min(needed, remaining)
self.buf[self.offset:self.offset+copy] = data[0:copy]
start_i = offset_i
end_i = start_i + copy
start_o = self.offset
end_o = start_o + copy
self.buf[start_o:end_o] = data[start_i:end_i]
offset_i += copy
remaining -= copy
self.offset += copy
if self.offset >= self.size:
if self.offset == self.size:
self.sock.send(self.buf)
self.offset = 0