X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=python%2Fashd%2Fscgi.py;h=4583fa73769e0ec6f94f5f71bf511e878d9d32d8;hb=1b16086880096c31abd31fa2dae40e5b36789162;hp=9357e9d1b317e829bacc7d77f12884b5a0e18e50;hpb=c06db49a3a4bfbf14b1661b667e1ed1cbab2bcd0;p=ashd.git diff --git a/python/ashd/scgi.py b/python/ashd/scgi.py index 9357e9d..4583fa7 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: @@ -74,9 +78,7 @@ def wrapwsgi(handler): resp = [] respsent = [] - def write(data): - if not data: - return + def flushreq(): if not respsent: if not resp: raise Exception, "Trying to write data before starting response." @@ -86,8 +88,16 @@ def wrapwsgi(handler): for nm, val in headers: sk.write("%s: %s\n" % (nm, val)) sk.write("\n") - sk.write(data) - sk.flush() + + def write(data): + if not data: + return + try: + flushreq() + sk.write(data) + sk.flush() + except IOError: + raise closed() def startreq(status, headers, exc_info = None): if resp: @@ -106,7 +116,8 @@ def wrapwsgi(handler): try: for data in respiter: write(data) - write("") + if resp: + flushreq() finally: if hasattr(respiter, "close"): respiter.close()