Fix bugs in OutputBuffer
This commit is contained in:
parent
ee3ed2bff8
commit
97050eafe4
1 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue