[Twisted-Python] [PATCH] A More Compatible Timeout
Moshe Zadka
m at moshez.org
Sun May 11 08:40:20 MDT 2003
This patch is functionally the same, but uses timeoutCall
and timeoutPeriod instead of timeout and terminateConnection.
Index: twisted/protocols/http.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/http.py,v
retrieving revision 1.79
diff -u -r1.79 http.py
--- twisted/protocols/http.py 8 May 2003 16:28:09 -0000 1.79
+++ twisted/protocols/http.py 11 May 2003 14:37:42 -0000
@@ -864,6 +864,7 @@
__header = ''
__first_line = 1
__content = None
+ timeoutCall = None
# set in instances or subclasses
requestFactory = Request
@@ -873,7 +874,14 @@
# the request queue
self.requests = []
+ def connectionMade(self):
+ self.timeoutPeriod = self.factory.timeoutPeriod
+ self.timeoutCall = reactor.callLater(self.timeoutPeriod,
+ self.transport.loseConnection)
+
def lineReceived(self, line):
+ if self.timeoutCall:
+ self.timeoutCall.reset(self.timeoutPeriod)
if self.__first_line:
# if this connection is not persistent, drop any data which
# the client (illegally) sent after the last request.
@@ -944,8 +952,13 @@
req = self.requests[-1]
req.requestReceived(command, path, version)
+ if self.timeoutCall:
+ self.timeoutCall.cancel()
+ self.timeoutCall = None
def rawDataReceived(self, data):
+ if self.timeoutCall:
+ self.timeoutCall.reset(self.timeoutPeriod)
if len(data) < self.length:
self.requests[-1].handleContentChunk(data)
self.length = self.length - len(data)
@@ -1000,6 +1013,9 @@
# notify next request it can start writing
if self.requests:
self.requests[0].noLongerQueued()
+ else:
+ self.timeoutCall = reactor.callLater(self.timeoutPeriod,
+ self.transport.loseConnection)
else:
self.transport.loseConnection()
@@ -1012,6 +1028,7 @@
"""Factory for HTTP server."""
protocol = HTTPChannel
+ timeoutPeriod = 60
logPath = None
--
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/
More information about the Twisted-Python
mailing list