Skip to content

Commit

Permalink
The ugliest fix for issue beeware#116 I could imagine.
Browse files Browse the repository at this point in the history
  • Loading branch information
odahoda committed Dec 14, 2023
1 parent d954036 commit 06c71af
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/gbulb/transports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import collections
import socket
import subprocess
from asyncio import CancelledError, InvalidStateError, base_subprocess, transports
from asyncio import BufferedProtocol, CancelledError, InvalidStateError, base_subprocess, transports


class BaseTransport(transports.BaseTransport):
Expand Down Expand Up @@ -124,7 +124,21 @@ def _create_read_future(self, size):

def _submit_read_data(self, data):
if data:
self._protocol.data_received(data)
if isinstance(self._protocol, BufferedProtocol):
# This is the most inefficient way to support
# BufferedProtocol (which was introduced as a more
# efficient interface than the regular
# Protocol). Doing it properly would involve using
# some kind of sock_recv_into method, but I don't
# understand the gbulb code well enough to do this.
while data:
buf = self._protocol.get_buffer(len(data))
n = min(len(buf), len(data))
buf[0:n] = data[0:n]
self._protocol.buffer_updated(n)
data = data[n:]
else:
self._protocol.data_received(data)
else:
keep_open = self._protocol.eof_received()
if not keep_open:
Expand Down

0 comments on commit 06c71af

Please sign in to comment.