From f35d639347e9d3e13510c12cddf81c18286e742d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com> Date: Wed, 10 Feb 2010 20:44:52 +0000 Subject: [PATCH] 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 --- neo/connection.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/neo/connection.py b/neo/connection.py index a5f7a060..db5a0937 100644 --- a/neo/connection.py +++ b/neo/connection.py @@ -259,6 +259,7 @@ class Connection(BaseConnection): def analyse(self): """Analyse received data.""" while True: + # parse a packet try: packet = Packets.parse(self.read_buf) if packet is None: @@ -266,7 +267,7 @@ class Connection(BaseConnection): except PacketMalformedError, msg: self.handler._packetMalformed(self, packet, msg) return - + self.read_buf = self.read_buf[len(packet):] # Remove idle events, if appropriate packets were received. for msg_id in (None, packet.getId()): @@ -274,17 +275,14 @@ class Connection(BaseConnection): if event is not None: self.em.removeIdleEvent(event) - try: - packet_type = packet.getType() - if packet_type == Packets.Ping: - # Send a pong notification - self.answer(Packets.Pong(), packet.getId()) - elif packet_type != Packets.Pong: - # Skip PONG packets, its only purpose is to drop IdleEvent - # generated upong ping. - self._queue.append(packet) - finally: - self.read_buf = self.read_buf[len(packet):] + packet_type = packet.getType() + if packet_type == Packets.Ping: + # Send a pong notification + self.answer(Packets.Pong(), packet.getId()) + elif packet_type != Packets.Pong: + # Skip PONG packets, its only purpose is to drop IdleEvent + # generated upong ping. + self._queue.append(packet) def hasPendingMessages(self): """ -- 2.30.9