[Twisted-Python] Submitted for your consideration

Jp Calderone exarkun at intarweb.us
Wed Jun 11 05:52:16 EDT 2003


  Attached is a patch to add timeout support to t.web (via a minor
HTTPChannel change).

  The performance impact should be light, though it does impose an extra
function call per received line.  If this is found to unacceptable, I do not
thing it would be unreasonable to change the "__lastReceived" attribute's
name, document it as public, and require the update be made inline.

  Jp

-- 
Seduced, shaggy Samson snored.
She scissored short.  Sorely shorn,
Soon shackled slave, Samson sighed,
Silently scheming,
Sightlessly seeking
Some savage, spectacular suicide.
                -- Stanislaw Lem, "Cyberiad"
-------------- next part --------------
Index: protocols/http.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/http.py,v
retrieving revision 1.80
diff -u -r1.80 http.py
--- protocols/http.py	17 May 2003 20:54:12 -0000	1.80
+++ protocols/http.py	11 Jun 2003 09:46:39 -0000
@@ -47,6 +47,7 @@
 
 # twisted imports
 from twisted.internet import interfaces, reactor, protocol
+from twisted.protocols import policies
 from twisted.python import log
 
 
@@ -856,7 +857,7 @@
         pass
 
 
-class HTTPChannel(basic.LineReceiver):
+class HTTPChannel(basic.LineReceiver, policies.TimeoutMixin):
     """A receiver for HTTP requests."""
 
     length = 0
@@ -868,12 +869,19 @@
     # set in instances or subclasses
     requestFactory = Request
 
+    # Timeout connections after 12 hours of inactivity
+    timeOut = 60 * 60 * 12
 
     def __init__(self):
         # the request queue
         self.requests = []
 
+    def connectionMade(self):
+        self.setTimeout(self.timeOut)
+    
     def lineReceived(self, line):
+        self.resetTimeout()
+
         if self.__first_line:
             # if this connection is not persistent, drop any data which
             # the client (illegally) sent after the last request.
@@ -1004,6 +1012,7 @@
             self.transport.loseConnection()
 
     def connectionLost(self, reason):
+        self.setTimeout(None)
         for request in self.requests:
             request.connectionLost(reason)
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030611/18f4347d/attachment.pgp 


More information about the Twisted-Python mailing list