changeset 4418:db692d99e4d1

standalone server: be more specific when catching socket exceptions, treat socket errors in http header emission in the same way
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 08 Nov 2008 14:36:38 +0100
parents fb0f0e80ba26
children d85005213fd9
files MoinMoin/request/request_standalone.py
diffstat 1 files changed, 29 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/request_standalone.py	Fri Nov 07 08:19:28 2008 +0100
+++ b/MoinMoin/request/request_standalone.py	Sat Nov 08 14:36:38 2008 +0100
@@ -7,12 +7,19 @@
     @license: GNU GPL, see COPYING for details.
 """
 import cgi
+import socket
+import errno
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
 from MoinMoin.request import RequestBase, RemoteClosedConnection
 
+# socket errors we just map to RemoteClosedConnection:
+socket_errors = [errno.ECONNABORTED, errno.ECONNRESET,
+                 errno.EPIPE, ]
+
+
 class Request(RequestBase):
     """ specialized on StandAlone Server (MoinMoin.server.server_standalone) requests """
     script_name = ''
@@ -81,15 +88,22 @@
         data = self.encode(data)
         try:
             self.wfile.write(data)
-        except Exception:
-            raise RemoteClosedConnection()
+        except socket.error, err:
+            if err.args[0] in socket_errors:
+                raise RemoteClosedConnection()
+            raise
 
     def flush(self):
-        self.wfile.flush()
+        try:
+            self.wfile.flush()
+        except socket.error, err:
+            if err.args[0] in socket_errors:
+                raise RemoteClosedConnection()
+            raise
 
     def finish(self):
         RequestBase.finish(self)
-        self.wfile.flush()
+        self.flush()
 
     # Headers ----------------------------------------------------------
 
@@ -99,10 +113,15 @@
         status = st_header.split(':', 1)[1].lstrip()
         status_code, status_msg = status.split(' ', 1)
         status_code = int(status_code)
-        self.sareq.send_response(status_code, status_msg)
-        for header in other_headers:
-            key, value = header.split(':', 1)
-            value = value.lstrip()
-            self.sareq.send_header(key, value)
-        self.sareq.end_headers()
+        try:
+            self.sareq.send_response(status_code, status_msg)
+            for header in other_headers:
+                key, value = header.split(':', 1)
+                value = value.lstrip()
+                self.sareq.send_header(key, value)
+            self.sareq.end_headers()
+        except socket.error, err:
+            if err.args[0] in socket_errors:
+                raise RemoteClosedConnection()
+            raise