[CalendarServer-changes] [5510] CalendarServer/branches/users/wsanchez/deployment/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 22 16:13:47 PDT 2010


Revision: 5510
          http://trac.macosforge.org/projects/calendarserver/changeset/5510
Author:   glyph at apple.com
Date:     2010-04-22 16:13:43 -0700 (Thu, 22 Apr 2010)
Log Message:
-----------
Honor maxAccepts as trunk does.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py

Added Paths:
-----------
    CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/maxaccept.py

Added: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/maxaccept.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/maxaccept.py	                        (rev 0)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/maxaccept.py	2010-04-22 23:13:43 UTC (rev 5510)
@@ -0,0 +1,86 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from twisted.application import internet
+from twisted.internet import tcp, ssl
+
+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)
+
+
+
+class MaxAcceptTCPPort(MaxAcceptPortMixin, tcp.Port):
+    """
+    Use for non-inheriting tcp ports.
+    """
+
+
+
+class MaxAcceptSSLPort(MaxAcceptPortMixin, ssl.Port):
+    """
+    Use for non-inheriting SSL ports.
+    """
+
+
+
+class MaxAcceptTCPServer(internet.TCPServer):
+    """
+    TCP server which will uses MaxAcceptTCPPorts.
+
+    @ivar myPort: When running, this is set to the L{IListeningPort} being
+        managed by this service.
+    """
+
+    def __init__(self, *args, **kwargs):
+        internet.TCPServer.__init__(self, *args, **kwargs)
+        self.args[1].myServer = self
+        self.backlog = self.kwargs.get("backlog", None)
+        self.interface = self.kwargs.get("interface", None)
+
+
+    def _getPort(self):
+        from twisted.internet import reactor
+
+        port = MaxAcceptTCPPort(self.args[0], self.args[1], self.backlog, self.interface, reactor)
+        port.startListening()
+        self.myPort = port
+        return port
+
+
+class MaxAcceptSSLServer(internet.SSLServer):
+    """
+    SSL server which will uses MaxAcceptSSLPorts.
+    """
+
+    def __init__(self, *args, **kwargs):
+        internet.SSLServer.__init__(self, *args, **kwargs)
+        self.args[1].myServer = self
+        self.backlog = self.kwargs.get("backlog", None)
+        self.interface = self.kwargs.get("interface", None)
+
+    def _getPort(self):
+        port = MaxAcceptSSLPort(self.args[0], self.args[1], self.args[2], self.backlog, self.interface, self.reactor)
+        port.startListening()
+        self.myPort = port
+        return port

Modified: CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py
===================================================================
--- CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py	2010-04-22 22:19:07 UTC (rev 5509)
+++ CalendarServer/branches/users/wsanchez/deployment/twistedcaldav/metafd.py	2010-04-22 23:13:43 UTC (rev 5510)
@@ -16,12 +16,13 @@
 ##
 
 from twisted.internet.tcp import Server
-from twisted.application.internet import TCPServer
 
 from twisted.application.service import MultiService, Service
 
 from twisted.web2.channel.http import HTTPFactory
 
+from twistedcaldav.maxaccept import MaxAcceptTCPServer
+
 from twistedcaldav.sendfdport import (
     InheritedPort, InheritedSocketDispatcher, InheritingProtocolFactory)
 
@@ -161,11 +162,11 @@
 
     def addPortService(self, description, port, interface, backlog):
         """
-        Add a L{TCPServer} to bind a TCP port to a socket description.
+        Add a L{MaxAcceptTCPServer} to bind a TCP port to a socket description.
         """
         lipf = LimitingInheritingProtocolFactory(self, description)
         self.factories.append(lipf)
-        svr = TCPServer(
+        svr = MaxAcceptTCPServer(
             port, lipf,
             interface=interface,
             backlog=backlog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100422/a0c3f8b0/attachment.html>


More information about the calendarserver-changes mailing list