Commit f35d6393 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Update read_buf as soon as possible, remove a useless try/finally, .

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1702 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a0d9f25d
...@@ -259,6 +259,7 @@ class Connection(BaseConnection): ...@@ -259,6 +259,7 @@ class Connection(BaseConnection):
def analyse(self): def analyse(self):
"""Analyse received data.""" """Analyse received data."""
while True: while True:
# parse a packet
try: try:
packet = Packets.parse(self.read_buf) packet = Packets.parse(self.read_buf)
if packet is None: if packet is None:
...@@ -266,7 +267,7 @@ class Connection(BaseConnection): ...@@ -266,7 +267,7 @@ class Connection(BaseConnection):
except PacketMalformedError, msg: except PacketMalformedError, msg:
self.handler._packetMalformed(self, packet, msg) self.handler._packetMalformed(self, packet, msg)
return return
self.read_buf = self.read_buf[len(packet):]
# Remove idle events, if appropriate packets were received. # Remove idle events, if appropriate packets were received.
for msg_id in (None, packet.getId()): for msg_id in (None, packet.getId()):
...@@ -274,17 +275,14 @@ class Connection(BaseConnection): ...@@ -274,17 +275,14 @@ class Connection(BaseConnection):
if event is not None: if event is not None:
self.em.removeIdleEvent(event) self.em.removeIdleEvent(event)
try: packet_type = packet.getType()
packet_type = packet.getType() if packet_type == Packets.Ping:
if packet_type == Packets.Ping: # Send a pong notification
# Send a pong notification self.answer(Packets.Pong(), packet.getId())
self.answer(Packets.Pong(), packet.getId()) elif packet_type != Packets.Pong:
elif packet_type != Packets.Pong: # Skip PONG packets, its only purpose is to drop IdleEvent
# Skip PONG packets, its only purpose is to drop IdleEvent # generated upong ping.
# generated upong ping. self._queue.append(packet)
self._queue.append(packet)
finally:
self.read_buf = self.read_buf[len(packet):]
def hasPendingMessages(self): def hasPendingMessages(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment