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):
self.read_buf = ""
self.write_buf = ""
self.cur_id = 0
self.peer_id = 0
self.event_dict = {}
self.aborted = False
self.uuid = None
......@@ -191,6 +192,12 @@ class Connection(BaseConnection):
def setUUID(self, uuid):
self.uuid = uuid
def setPeerId(self, peer_id):
self.peer_id = peer_id
def getPeerId(self):
return self.peer_id
def _getNextId(self):
next_id = self.cur_id
# Deal with an overflow.
......@@ -403,8 +410,10 @@ class Connection(BaseConnection):
return msg_id
@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 """
if msg_id is None:
msg_id = self.getPeerId()
packet.setId(msg_id)
self._addPacket(packet)
......
......@@ -68,6 +68,7 @@ class EventHandler(object):
except KeyError:
raise UnexpectedPacketError('no handler found')
args = packet.decode() or ()
conn.setPeerId(packet.getId())
method(conn, packet, *args)
except UnexpectedPacketError, e:
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