[CalendarServer-changes] [14762] twext/trunk/twext/internet/socketfile.py

source_changes at macosforge.org source_changes at macosforge.org
Tue May 5 11:39:40 PDT 2015


Revision: 14762
          http://trac.calendarserver.org//changeset/14762
Author:   sagen at apple.com
Date:     2015-05-05 11:39:40 -0700 (Tue, 05 May 2015)
Log Message:
-----------
Intercept port.doRead

Modified Paths:
--------------
    twext/trunk/twext/internet/socketfile.py

Modified: twext/trunk/twext/internet/socketfile.py
===================================================================
--- twext/trunk/twext/internet/socketfile.py	2015-05-05 18:38:39 UTC (rev 14761)
+++ twext/trunk/twext/internet/socketfile.py	2015-05-05 18:39:40 UTC (rev 14762)
@@ -25,7 +25,7 @@
 
 from twisted.application import service
 from twisted.internet import endpoints
-from twisted.internet.defer import succeed, inlineCallbacks
+from twisted.internet.defer import inlineCallbacks
 
 from twext.python.log import Logger
 
@@ -33,51 +33,14 @@
 
 
 
-# class MaxAcceptPortMixin(object):
-#     """
-#     Mixin for resetting maxAccepts.
-#     """
-#     def doRead(self):
-#         self.numberAccepts = min(
-#             self.factory.maxRequests - self.factory.outstandingRequests,
-#             self.factory.maxAccepts
-#         )
-#         tcp.Port.doRead(self)
+def maxAcceptDoRead(self):
+    self.numberAccepts = min(
+        self.factory.maxRequests - self.factory.outstandingRequests,
+        self.factory.maxAccepts
+    )
+    self.realDoRead()
 
 
-
-# class MaxAcceptTCPPort(MaxAcceptPortMixin, tcp.Port):
-#     """
-#     Use for non-inheriting tcp ports.
-#     """
-
-
-
-
-
-
-
-def _allConnectionsClosed(protocolFactory):
-    """
-    Check to see if protocolFactory implements allConnectionsClosed( ) and
-    if so, call it.  Otherwise, return immediately.
-    This allows graceful shutdown by waiting for all requests to be completed.
-
-    @param protocolFactory: (usually) an HTTPFactory implementing
-        allConnectionsClosed which returns a Deferred which fires when all
-        connections are closed.
-
-    @return: A Deferred firing None when all connections are closed, or
-        immediately if the given factory does not track its connections (e.g.
-        InheritingProtocolFactory)
-    """
-    if hasattr(protocolFactory, "allConnectionsClosed"):
-        return protocolFactory.allConnectionsClosed()
-    return succeed(None)
-
-
-
-
 class MaxAcceptSocketFileServer(service.Service):
     """
     Socket File server
@@ -102,7 +65,13 @@
         )
         self.myPort = yield endpoint.listen(self.protocolFactory)
 
+        # intercept doRead() to set numberAccepts
+        self.myPort.realDoRead = self.myPort.doRead
+        self.myPort.doRead = maxAcceptDoRead.__get__(
+            self.myPort, self.myPort.__class__
+        )
 
+
     @inlineCallbacks
     def stopService(self):
         """
@@ -113,4 +82,6 @@
         """
         if self.myPort is not None:
             yield self.myPort.stopListening()
-        yield _allConnectionsClosed(self.protocolFactory)
+
+        if hasattr(self.protocolFactory, "allConnectionsClosed"):
+            yield self.protocolFactory.allConnectionsClosed()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150505/ff64ab7b/attachment.html>


More information about the calendarserver-changes mailing list