summaryrefslogtreecommitdiffstats
path: root/Demo/rpc
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-12-15 21:44:31 (GMT)
committerGuido van Rossum <guido@python.org>1992-12-15 21:44:31 (GMT)
commit16b22193e6677dec27719172e92c0d83cfd28366 (patch)
treee43181d7fed7eb483e592b2bae0f9e5dbbaa166e /Demo/rpc
parent63ae96e3d7a1bf545bdf2c4484aa1cb065e920ea (diff)
downloadcpython-16b22193e6677dec27719172e92c0d83cfd28366.zip
cpython-16b22193e6677dec27719172e92c0d83cfd28366.tar.gz
cpython-16b22193e6677dec27719172e92c0d83cfd28366.tar.bz2
Add timeout and retry to UDP version of protocol
Diffstat (limited to 'Demo/rpc')
-rw-r--r--Demo/rpc/rpc.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/Demo/rpc/rpc.py b/Demo/rpc/rpc.py
index 607a25e..6d3fade 100644
--- a/Demo/rpc/rpc.py
+++ b/Demo/rpc/rpc.py
@@ -246,6 +246,7 @@ class RawUDPClient(Client):
p.pack_callheader(xid, self.prog, self.vers, proc, cred, verf)
def do_call(self, *rest):
+ from select import select
if len(rest) == 0:
bufsize = 8192
elif len(rest) > 1:
@@ -253,16 +254,26 @@ class RawUDPClient(Client):
else:
bufsize = rest[0] + 512
call = self.packer.get_buf()
+ timeout = 1
+ count = 5
self.sock.send(call)
- # XXX What about time-out and retry?
- reply = self.sock.recv(bufsize)
- u = self.unpacker
- u.reset(reply)
- xid, verf = u.unpack_replyheader()
- if xid <> self.lastxid:
- # XXX Should assume it's an old reply
- raise RuntimeError, 'wrong xid in reply ' + `xid` + \
- ' instead of ' + `self.lastxid`
+ while 1:
+ r, w, x = select([self.sock], [], [], timeout)
+ if self.sock not in r:
+ count = count - 1
+ if count < 0: raise RuntimeError, 'timeout'
+ if timeout < 25: timeout = timeout *2
+ print 'RESEND', timeout, count
+ self.sock.send(call)
+ continue
+ reply = self.sock.recv(bufsize)
+ u = self.unpacker
+ u.reset(reply)
+ xid, verf = u.unpack_replyheader()
+ if xid <> self.lastxid:
+ print 'BAD xid'
+ continue
+ break
def end_call(self):
self.unpacker.done()