Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/python-bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoerg Steffens <joerg.steffens@bareos.com>2017-02-22 11:15:02 +0300
committerJoerg Steffens <joerg.steffens@bareos.com>2017-02-22 11:15:02 +0300
commit25fd56e1d128a2b5008f1384a7b1e8f9fe354668 (patch)
tree8fcafcd65c0358ec937635e6bc61b406c4ecec00
parent94de78eddbb0f8c1ccd3126675f0cd3844bb7a94 (diff)
speed up for receiving long, multiline messages
Until now, the full receive buffer have been checked for a end of message regex. Now only the last line of the receice buffer plus the newly received part is checked for the regex.
-rw-r--r--bareos/bsock/lowlevel.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/bareos/bsock/lowlevel.py b/bareos/bsock/lowlevel.py
index 042fa68..61b9edb 100644
--- a/bareos/bsock/lowlevel.py
+++ b/bareos/bsock/lowlevel.py
@@ -195,13 +195,18 @@ class LowLevel(object):
else:
# header is the length of the next message
length = header
- self.receive_buffer += self.recv_submsg(length)
+ submsg = self.recv_submsg(length)
+ # check for regex in new submsg
+ # and last line in old message,
+ # which might have been incomplete without new submsg.
+ lastlineindex = self.receive_buffer.rfind('\n') + 1
+ self.receive_buffer += submsg
+ match = re.search(regex, self.receive_buffer[lastlineindex:], re.MULTILINE)
# Bareos indicates end of command result by line starting with 4 digits
- match = re.search(regex, self.receive_buffer, re.MULTILINE)
if match:
self.logger.debug("msg \"{0}\" matches regex \"{1}\"".format(self.receive_buffer.strip(), regex))
- result = self.receive_buffer[0:match.end()]
- self.receive_buffer = self.receive_buffer[match.end()+1:]
+ result = self.receive_buffer[0:lastlineindex] + self.receive_buffer[lastlineindex:match.end()]
+ self.receive_buffer = self.receive_buffer[lastlineindex+match.end()+1:]
return result
#elif re.search("^\d\d\d\d .*$", msg, re.MULTILINE):
#return msg