[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] Catch EPIPE in handle and finish.
commit 22ecf31753d059262dcb254d274f65ca5c4d4ceb
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Sat Jul 28 16:29:56 2012 -0700
Catch EPIPE in handle and finish.
---
facilitator | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/facilitator b/facilitator
index 99ef63d..3695b52 100755
--- a/facilitator
+++ b/facilitator
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import SocketServer
+import errno
import getopt
import os
import socket
@@ -126,6 +127,23 @@ class RegSet(object):
finally:
self.cv.release()
+# A decorator to ignore "broken pipe" errors.
+def catch_epipe(fn):
+ def ret(self, *args):
+ try:
+ return fn(self, *args)
+ except socket.error, e:
+ try:
+ err_num = e.errno
+ except AttributeError:
+ # Before Python 2.6, exception can be a pair.
+ err_num, errstr = e
+ except:
+ raise
+ if err_num != errno.EPIPE:
+ raise
+ return ret
+
class Handler(SocketServer.StreamRequestHandler):
def __init__(self, *args, **kwargs):
self.deadline = time.time() + CLIENT_TIMEOUT
@@ -166,6 +184,7 @@ class Handler(SocketServer.StreamRequestHandler):
if buflen >= READLINE_MAX_LENGTH:
raise socket.error("readline: refusing to buffer %d bytes (last read was %d bytes)" % (buflen, len(data)))
+ @catch_epipe
def handle(self):
num_lines = 0
while True:
@@ -239,6 +258,8 @@ class Handler(SocketServer.StreamRequestHandler):
self.send_ok()
return True
+ finish = catch_epipe(SocketServer.StreamRequestHandler.finish)
+
class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits