From 1a860c6ffdaad6b6ee38369380de5ed15f92a8f8 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 19 May 2023 01:57:20 +0200 Subject: [PATCH] Add EOF signal on buffer close --- RNS/Buffer.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/RNS/Buffer.py b/RNS/Buffer.py index ac13626..0dd7e18 100644 --- a/RNS/Buffer.py +++ b/RNS/Buffer.py @@ -1,6 +1,7 @@ from __future__ import annotations import bz2 import sys +import time import threading from threading import RLock import struct @@ -65,6 +66,7 @@ class StreamDataMessage(MessageBase): self.compressed = (0x4000 & self.stream_id) > 0 self.stream_id = self.stream_id & 0x3fff self.data = raw[2:] + if self.compressed: self.data = bz2.decompress(self.data) @@ -207,6 +209,15 @@ class RawChannelWriter(RawIOBase, AbstractContextManager): return 0 def close(self): + try: + link_rtt = self._channel._outlet.link.rtt + timeout = time.time() + (link_rtt * len(self._channel._tx_ring) * 1) + except Exception as e: + timeout = time.time() + 15 + + while time.time() < timeout and not self._channel.is_ready_to_send(): + time.sleep(0.05) + self._eof = True self.write(bytes())