Adjusted connection class. overrode send_data data, to break up large frames into chunks of 2k bytes.
This commit is contained in:
@@ -14,6 +14,7 @@ class PacketServerConnection(Connection):
|
|||||||
|
|
||||||
connection_subscribers = []
|
connection_subscribers = []
|
||||||
receive_subscribers = []
|
receive_subscribers = []
|
||||||
|
max_send_size = 2000
|
||||||
|
|
||||||
def __init__(self, port, call_from, call_to, incoming=False):
|
def __init__(self, port, call_from, call_to, incoming=False):
|
||||||
super().__init__(port, call_from, call_to, incoming=incoming)
|
super().__init__(port, call_from, call_to, incoming=incoming)
|
||||||
@@ -62,6 +63,19 @@ class PacketServerConnection(Connection):
|
|||||||
def send_data(self, data: Union[bytes, bytearray]):
|
def send_data(self, data: Union[bytes, bytearray]):
|
||||||
logging.debug(f"sending data: {data}")
|
logging.debug(f"sending data: {data}")
|
||||||
self.connection_last_activity = datetime.datetime.now(datetime.UTC)
|
self.connection_last_activity = datetime.datetime.now(datetime.UTC)
|
||||||
|
if len(data) > self.max_send_size:
|
||||||
|
logging.debug(f"Large frame detected {len(data)} breaking it up into chunks")
|
||||||
|
index = 0
|
||||||
|
counter = 0
|
||||||
|
while index <= len(data):
|
||||||
|
logging.debug(f"Sending chunk {counter}")
|
||||||
|
if (len(data) - index) < self.max_send_size:
|
||||||
|
super().send_data(data[index:])
|
||||||
|
break
|
||||||
|
super().send_data(data[index:index + self.max_send_size])
|
||||||
|
index = index + self.max_send_size
|
||||||
|
counter = counter + 1
|
||||||
|
else:
|
||||||
super().send_data(data)
|
super().send_data(data)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -289,20 +303,27 @@ def send_response(conn: PacketServerConnection, response: Response, original_req
|
|||||||
if conn.state.name == "CONNECTED" and not conn.closing:
|
if conn.state.name == "CONNECTED" and not conn.closing:
|
||||||
|
|
||||||
# figure out compression setting based on request
|
# figure out compression setting based on request
|
||||||
|
logging.debug("Determining compression of response")
|
||||||
comp = compression
|
comp = compression
|
||||||
|
logging.debug(f"Default comp: {comp}")
|
||||||
|
logging.debug(f"Original vars: {original_request.vars}")
|
||||||
if 'C' in original_request.vars:
|
if 'C' in original_request.vars:
|
||||||
|
logging.debug(f"Detected compression header in original request: {original_request.vars['C']}")
|
||||||
val = original_request.vars['C']
|
val = original_request.vars['C']
|
||||||
for i in Message.CompressionType:
|
for i in Message.CompressionType:
|
||||||
|
logging.debug(f"Checking type: {i}")
|
||||||
if str(val).strip().upper() == i.name:
|
if str(val).strip().upper() == i.name:
|
||||||
comp = i
|
comp = i
|
||||||
|
logging.debug(f"matched compression with var to {comp}")
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
if int(val) == i.value:
|
if int(val) == i.value:
|
||||||
comp = i
|
comp = i
|
||||||
|
logging.debug(f"matched compression with var to {comp}")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
response.compression = comp
|
response.compression = comp
|
||||||
|
logging.debug(f"Final compression: {response.compression}")
|
||||||
|
|
||||||
logging.debug(f"sending response: {response}, {response.compression}, {response.payload}")
|
logging.debug(f"sending response: {response}, {response.compression}, {response.payload}")
|
||||||
conn.send_data(response.pack())
|
conn.send_data(response.pack())
|
||||||
|
|||||||
Reference in New Issue
Block a user