[tor-commits] [flashproxy/master] Make a recv timeout abstraction.
dcf at torproject.org
dcf at torproject.org
Fri Aug 31 11:39:36 UTC 2012
commit 9ed405581cb0e093e24cb2251f93911669e95e19
Author: David Fifield <david at bamsoftware.com>
Date: Sat Jul 7 07:10:14 2012 -0700
Make a recv timeout abstraction.
---
facilitator | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/facilitator b/facilitator
index 61129c7..26c964d 100755
--- a/facilitator
+++ b/facilitator
@@ -14,6 +14,9 @@ DEFAULT_LISTEN_PORT = 9002
DEFAULT_RELAY_PORT = 9001
DEFAULT_LOG_FILENAME = "facilitator.log"
+# Don't indulge clients for more than this many seconds.
+CLIENT_TIMEOUT = 1.0
+
LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
class options(object):
@@ -110,10 +113,22 @@ def format_addr(addr):
return u"%s:%d" % (host, port)
class Handler(SocketServer.StreamRequestHandler):
+ def __init__(self, *args, **kwargs):
+ self.deadline = time.time() + CLIENT_TIMEOUT
+ SocketServer.StreamRequestHandler.__init__(self, *args, **kwargs)
+
+ def recv(self):
+ timeout = self.deadline - time.time()
+ self.connection.settimeout(timeout)
+ return self.connection.recv(1024)
+
+ def readline(self):
+ while True:
+ self.connection.settimeout(timeout)
+
def handle(self):
- self.connection.settimeout(1.0)
while True:
- data = self.connection.recv(1024)
+ data = self.recv()
print repr(data)
class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
More information about the tor-commits
mailing list