From 81a0ca30bf866751d7a389ea322ddff2de64db1b Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sat, 9 Apr 2011 10:58:43 +0200 Subject: [PATCH] python: Rethrow special IOErrors when a client has aborted. --- python/ashd-wsgi | 12 ++++++++++-- python/ashd/scgi.py | 13 ++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/python/ashd-wsgi b/python/ashd-wsgi index 92a254a..042bf3f 100755 --- a/python/ashd-wsgi +++ b/python/ashd-wsgi @@ -36,6 +36,10 @@ else: sys.exit(1) handler = handlermod.application +class closed(IOError): + def __init__(self): + super(closed, self).__init__("The client has closed the connection.") + cwd = os.getcwd() def absolutify(path): if path[0] != '/': @@ -74,6 +78,7 @@ def unquoteurl(url): else: buf += c return buf + def dowsgi(req): env = {} env["wsgi.version"] = 1, 0 @@ -130,8 +135,11 @@ def dowsgi(req): if not data: return flushreq() - req.sk.write(data) - req.sk.flush() + try: + req.sk.write(data) + req.sk.flush() + except IOError: + raise closed() def startreq(status, headers, exc_info = None): if resp: diff --git a/python/ashd/scgi.py b/python/ashd/scgi.py index a4342d0..0bc7a57 100644 --- a/python/ashd/scgi.py +++ b/python/ashd/scgi.py @@ -4,6 +4,10 @@ import threading class protoerr(Exception): pass +class closed(IOError): + def __init__(self): + super(closed, self).__init__("The client has closed the connection.") + def readns(sk): hln = 0 while True: @@ -88,9 +92,12 @@ def wrapwsgi(handler): def write(data): if not data: return - flushreq() - sk.write(data) - sk.flush() + try: + flushreq() + sk.write(data) + sk.flush() + except IOError: + raise closed() def startreq(status, headers, exc_info = None): if resp: -- 2.11.0