ssnet: recover slightly more gracefully from an infinite forwarding loop.

If you 'telnet localhost 12300' weird things happen; someday we should
probably auto-detect and avoid that altogether.  But meanwhile, catch EPIPE
if it happens (it's irrelevant) and don't barf with a %d data type for a
value that can apparently sometimes be None.
This commit is contained in:
Avery Pennarun 2010-09-30 23:25:08 -07:00
parent 410b9d4229
commit 4bf4f70c67

View File

@ -35,7 +35,7 @@ def _nb_clean(func, *args):
try:
return func(*args)
except OSError, e:
if e.errno not in (errno.EWOULDBLOCK, errno.EAGAIN):
if e.errno not in (errno.EWOULDBLOCK, errno.EAGAIN, errno.EPIPE):
raise
else:
return None
@ -308,7 +308,7 @@ class Mux(Handler):
self.wsock.setblocking(False)
if self.outbuf and self.outbuf[0]:
wrote = _nb_clean(os.write, self.wsock.fileno(), self.outbuf[0])
debug2('mux wrote: %d/%d\n' % (wrote, len(self.outbuf[0])))
debug2('mux wrote: %r/%d\n' % (wrote, len(self.outbuf[0])))
if wrote:
self.outbuf[0] = self.outbuf[0][wrote:]
while self.outbuf and not self.outbuf[0]: