Skip to content

Commit 5b10813

Browse files
committed
optimize tcp udp recieve
1 parent 0da3b01 commit 5b10813

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

COMTool/conn/conn_tcp_udp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ def setVar(self, key, value = None):
319319
except Exception:
320320
text = "".join(re.findall('[\d\.]*', text))
321321
self.autoReconnectIntervalEdit.setText(text)
322-
323322

324323
def openCloseSerial(self):
325324
if self.busy:
@@ -500,6 +499,7 @@ def receiveDataProcess(self, conn, remote_addr:tuple = None):
500499
continue
501500
try:
502501
# length = max(1, self.conn.in_waiting)
502+
flush = True
503503
try:
504504
if protocolIsTcp:
505505
data = conn.recv(4096)
@@ -515,12 +515,14 @@ def receiveDataProcess(self, conn, remote_addr:tuple = None):
515515
except socket.timeout:
516516
data = None
517517
if data:
518+
if len(data) > 4096:
519+
flush = False
518520
t = time.time()
519521
# if length == 1 and not buffer: # just start receive
520522
# buffer += data
521523
# continue
522524
buffer += data
523-
if buffer and (time.time() - t > 0.001): # no new data in 1ms
525+
if flush or (buffer and (time.time() - t > 0.001)): # no new data in 0.1ms
524526
try:
525527
self.onReceived(buffer)
526528
except Exception as e:

0 commit comments

Comments
 (0)