[CalendarServer-changes] [5416] CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 30 14:10:33 PDT 2010


Revision: 5416
          http://trac.macosforge.org/projects/calendarserver/changeset/5416
Author:   glyph at apple.com
Date:     2010-03-30 14:10:32 -0700 (Tue, 30 Mar 2010)
Log Message:
-----------
Defer allocating extra meta FD sockets until startup, to avoid extra setup/teardown work in tests.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/caldav.py
    CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/test/test_caldav.py

Modified: CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/caldav.py	2010-03-30 20:58:26 UTC (rev 5415)
+++ CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/caldav.py	2010-03-30 21:10:32 UTC (rev 5416)
@@ -846,7 +846,7 @@
 
         for p in xrange(0, config.MultiProcess.ProcessCount):
             if config.UseMetaFD:
-                extraArgs = dict(metaFD=cl.dispatcher.addSocket())
+                extraArgs = dict(dispatcher=cl.dispatcher)
             else:
                 extraArgs = dict(inheritFDs=inheritFDs,
                                  inheritSSLFDs=inheritSSLFDs)
@@ -996,15 +996,15 @@
         on in the subprocess, and speaking TLS on the resulting sockets.
     @type inheritSSLFDs: C{list} of C{int}, or C{None}
 
-    @ivar metaFD: a UNIX socket which will be used to send file descriptors
-        down to the slave process.
+    @ivar dispatcher: a socket dispatcher to generate an inherited port from,
+        or C{None}.
 
-    @type metaFD: L{socket.socket}, or C{None}
+    @type dispatcher: L{InheritedSocketDispatcher} or C{NoneType}
     """
     prefix = "caldav"
 
     def __init__(self, twistd, tapname, configFile, id, interfaces,
-                 inheritFDs=None, inheritSSLFDs=None, metaFD=None):
+                 inheritFDs=None, inheritSSLFDs=None, dispatcher=None):
 
         self.twistd = twistd
 
@@ -1020,7 +1020,8 @@
                 return x
         self.inheritFDs = emptyIfNone(inheritFDs)
         self.inheritSSLFDs = emptyIfNone(inheritSSLFDs)
-        self.metaFD = metaFD
+        self.metaSocket = None
+        self.dispatcher = dispatcher
 
         self.interfaces = interfaces
 
@@ -1028,6 +1029,15 @@
         return '%s-%s' % (self.prefix, self.id)
 
 
+    def getMetaDescriptor(self):
+        """
+        Get the meta-socket file descriptor to inherit.
+        """
+        if self.metaSocket is None:
+            self.metaSocket = self.dispatcher.addSocket()
+        return self.metaSocket.fileno()
+
+
     def getFileDescriptors(self):
         """
         @return: a mapping of file descriptor numbers for the new (child)
@@ -1035,8 +1045,8 @@
         """
         fds = {}
         maybeMetaFD = []
-        if self.metaFD:
-            maybeMetaFD.append(self.metaFD.fileno())
+        if self.dispatcher is not None:
+            maybeMetaFD.append(self.getMetaDescriptor())
         for fd in self.inheritSSLFDs + self.inheritFDs + maybeMetaFD:
             fds[fd] = fd
         return fds
@@ -1090,11 +1100,11 @@
                 "-o", "InheritSSLFDs=%s" % (",".join(map(str, self.inheritSSLFDs)),)
             ])
 
-        if self.metaFD:
+        if self.dispatcher is not None:
             # XXX this FD is never closed in the parent.  should it be?
             # (should they *all* be?) -glyph
             args.extend([
-                    "-o", "MetaFD=%s" % (self.metaFD.fileno(),)
+                    "-o", "MetaFD=%s" % (self.getMetaDescriptor(),)
                 ])
 
         return args

Modified: CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/test/test_caldav.py
===================================================================
--- CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/test/test_caldav.py	2010-03-30 20:58:26 UTC (rev 5415)
+++ CalendarServer/branches/users/glyph/sendfdport/calendarserver/tap/test/test_caldav.py	2010-03-30 21:10:32 UTC (rev 5416)
@@ -988,17 +988,25 @@
         dspm         = DelayedStartupProcessMonitor()
         dspm.reactor = InMemoryProcessSpawner()
         class FakeFD:
+            def __init__(self, n):
+                self.fd = n
             def fileno(self):
-                return 4
+                return self.fd
 
+        class FakeDispatcher:
+            n = 3
+            def addSocket(self):
+                self.n += 1
+                return FakeFD(self.n)
+
         # Most arguments here will be ignored, so these are bogus values.
         slave = TwistdSlaveProcess(
-            twistd        = "bleh",
-            tapname       = "caldav",
-            configFile    = "/does/not/exist",
-            id            = 10,
-            interfaces    = '127.0.0.1',
-            metaFD        = FakeFD()
+            twistd     = "bleh",
+            tapname    = "caldav",
+            configFile = "/does/not/exist",
+            id         = 10,
+            interfaces = '127.0.0.1',
+            dispatcher = FakeDispatcher()
         )
 
         dspm.addProcessObject(slave, {})
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100330/397033b6/attachment-0001.html>


More information about the calendarserver-changes mailing list