Skip to content

Commit

Permalink
Disable cleanup at the beginning of the buffer for blob connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor Latanowicz committed Mar 27, 2023
1 parent 9c117ae commit 38d1646
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion indi/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ async def start(self):
self.process_message
)
self.blob_connection_handler = await self.blob_connection.connect(
self.process_message
self.process_message, for_blobs=True
)

asyncio.get_running_loop().create_task(
Expand Down
6 changes: 3 additions & 3 deletions indi/transport/buffer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import xml.etree.ElementTree as ET
from io import StringIO
from typing import Callable
from typing import Callable, Optional

from indi.message import IndiMessage

Expand All @@ -10,7 +10,7 @@

class Buffer:
def __init__(self) -> None:
self.max_buffer_size_before_frontal_cleanup = 2048
self.max_buffer_size_before_frontal_cleanup: Optional[int] = 2048
self.buffer = StringIO()
self.allowed_tags = [m.tag_name() for m in IndiMessage.all_message_classes()]

Expand Down Expand Up @@ -101,7 +101,7 @@ def process(self, callback: Callable[[IndiMessage], None]):
while self.data_len:
message, end = self._find_message_in_buffer()

if not message:
if not message and self.max_buffer_size_before_frontal_cleanup is not None:
if self.data_len > self.max_buffer_size_before_frontal_cleanup:
self._cleanup_beginning()
continue
Expand Down
8 changes: 6 additions & 2 deletions indi/transport/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ def __init__(
reader: asyncio.StreamReader,
writer: asyncio.StreamWriter,
callback: Callable[[IndiMessage], None],
for_blobs=False,
):
self.buffer = Buffer()
if for_blobs:
self.buffer.max_buffer_size_before_frontal_cleanup = None

self.reader, self.writer = reader, writer
self.callback = callback
self.sender_lock = asyncio.Lock()
Expand Down Expand Up @@ -53,7 +57,7 @@ def __init__(self, address: str = "127.0.0.1", port: int = 7624):
self.address = address
self.port = port

async def connect(self, callback: Callable[[IndiMessage], None]):
async def connect(self, callback: Callable[[IndiMessage], None], for_blobs=False):
reader, writer = await asyncio.open_connection(self.address, self.port)
handler = ConnectionHandler(reader, writer, callback)
handler = ConnectionHandler(reader, writer, callback, for_blobs=for_blobs)
return handler

0 comments on commit 38d1646

Please sign in to comment.