implement chunk handling for read data
This commit is contained in:
parent
cdc6f159bf
commit
21b67c6fd5
1 changed files with 4 additions and 1 deletions
|
@ -40,6 +40,7 @@ class XmppClientServerResponseHandler(ContentHandler):
|
||||||
elif name == (NS_XMPP_CAPS, 'c'):
|
elif name == (NS_XMPP_CAPS, 'c'):
|
||||||
for qname in attrs.getQNames():
|
for qname in attrs.getQNames():
|
||||||
self.capabilities[qname] = attrs.getValueByQName(qname)
|
self.capabilities[qname] = attrs.getValueByQName(qname)
|
||||||
|
# print(name, attrs.getQNames())
|
||||||
|
|
||||||
def endElementNS(self, name, qname):
|
def endElementNS(self, name, qname):
|
||||||
del self.inelem[-1]
|
del self.inelem[-1]
|
||||||
|
@ -110,14 +111,16 @@ class Xmpp(nagiosplugin.Resource):
|
||||||
|
|
||||||
def handle_xmpp_stanza(self, xmppsocket, message_str, timeout=0.1):
|
def handle_xmpp_stanza(self, xmppsocket, message_str, timeout=0.1):
|
||||||
xmppsocket.sendall(message_str.encode('utf-8'))
|
xmppsocket.sendall(message_str.encode('utf-8'))
|
||||||
|
chunks = []
|
||||||
while True:
|
while True:
|
||||||
rready, wready, xready = select([xmppsocket], [], [], timeout)
|
rready, wready, xready = select([xmppsocket], [], [], timeout)
|
||||||
if xmppsocket in rready:
|
if xmppsocket in rready:
|
||||||
data = xmppsocket.recv(4096)
|
data = xmppsocket.recv(4096)
|
||||||
if not data: break
|
if not data: break
|
||||||
self.parser.feed(data.decode('utf-8'))
|
chunks.append(data)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
self.parser.feed(b''.join(chunks).decode('utf-8'))
|
||||||
|
|
||||||
def handle_client(self, xmppsocket):
|
def handle_client(self, xmppsocket):
|
||||||
self.handle_xmpp_stanza(xmppsocket, (
|
self.handle_xmpp_stanza(xmppsocket, (
|
||||||
|
|
Loading…
Reference in a new issue