mirror of
https://github.com/python/cpython.git
synced 2025-09-11 03:07:01 +00:00
Add timeout and retry to UDP version of protocol
This commit is contained in:
parent
63ae96e3d7
commit
16b22193e6
1 changed files with 20 additions and 9 deletions
|
@ -246,6 +246,7 @@ class RawUDPClient(Client):
|
||||||
p.pack_callheader(xid, self.prog, self.vers, proc, cred, verf)
|
p.pack_callheader(xid, self.prog, self.vers, proc, cred, verf)
|
||||||
|
|
||||||
def do_call(self, *rest):
|
def do_call(self, *rest):
|
||||||
|
from select import select
|
||||||
if len(rest) == 0:
|
if len(rest) == 0:
|
||||||
bufsize = 8192
|
bufsize = 8192
|
||||||
elif len(rest) > 1:
|
elif len(rest) > 1:
|
||||||
|
@ -253,16 +254,26 @@ class RawUDPClient(Client):
|
||||||
else:
|
else:
|
||||||
bufsize = rest[0] + 512
|
bufsize = rest[0] + 512
|
||||||
call = self.packer.get_buf()
|
call = self.packer.get_buf()
|
||||||
|
timeout = 1
|
||||||
|
count = 5
|
||||||
self.sock.send(call)
|
self.sock.send(call)
|
||||||
# XXX What about time-out and retry?
|
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)
|
reply = self.sock.recv(bufsize)
|
||||||
u = self.unpacker
|
u = self.unpacker
|
||||||
u.reset(reply)
|
u.reset(reply)
|
||||||
xid, verf = u.unpack_replyheader()
|
xid, verf = u.unpack_replyheader()
|
||||||
if xid <> self.lastxid:
|
if xid <> self.lastxid:
|
||||||
# XXX Should assume it's an old reply
|
print 'BAD xid'
|
||||||
raise RuntimeError, 'wrong xid in reply ' + `xid` + \
|
continue
|
||||||
' instead of ' + `self.lastxid`
|
break
|
||||||
|
|
||||||
def end_call(self):
|
def end_call(self):
|
||||||
self.unpacker.done()
|
self.unpacker.done()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue