Commit 91ff3fef authored by Grégory Wisniewski's avatar Grégory Wisniewski

Make msg_id optional in Connection.answer().

The connection now store the last generated remote ID. If no msg_id is supplied to answer(), the last received ID will be used.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1568 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent dfef415e
...@@ -175,6 +175,7 @@ class Connection(BaseConnection): ...@@ -175,6 +175,7 @@ class Connection(BaseConnection):
self.read_buf = "" self.read_buf = ""
self.write_buf = "" self.write_buf = ""
self.cur_id = 0 self.cur_id = 0
self.peer_id = 0
self.event_dict = {} self.event_dict = {}
self.aborted = False self.aborted = False
self.uuid = None self.uuid = None
...@@ -191,6 +192,12 @@ class Connection(BaseConnection): ...@@ -191,6 +192,12 @@ class Connection(BaseConnection):
def setUUID(self, uuid): def setUUID(self, uuid):
self.uuid = uuid self.uuid = uuid
def setPeerId(self, peer_id):
self.peer_id = peer_id
def getPeerId(self):
return self.peer_id
def _getNextId(self): def _getNextId(self):
next_id = self.cur_id next_id = self.cur_id
# Deal with an overflow. # Deal with an overflow.
...@@ -403,8 +410,10 @@ class Connection(BaseConnection): ...@@ -403,8 +410,10 @@ class Connection(BaseConnection):
return msg_id return msg_id
@not_closed @not_closed
def answer(self, packet, msg_id): def answer(self, packet, msg_id=None):
""" Answer to a packet by re-using its ID for the packet answer """ """ Answer to a packet by re-using its ID for the packet answer """
if msg_id is None:
msg_id = self.getPeerId()
packet.setId(msg_id) packet.setId(msg_id)
self._addPacket(packet) self._addPacket(packet)
......
...@@ -68,6 +68,7 @@ class EventHandler(object): ...@@ -68,6 +68,7 @@ class EventHandler(object):
except KeyError: except KeyError:
raise UnexpectedPacketError('no handler found') raise UnexpectedPacketError('no handler found')
args = packet.decode() or () args = packet.decode() or ()
conn.setPeerId(packet.getId())
method(conn, packet, *args) method(conn, packet, *args)
except UnexpectedPacketError, e: except UnexpectedPacketError, e:
self.__unexpectedPacket(conn, packet, *e.args) self.__unexpectedPacket(conn, packet, *e.args)
......
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