<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14749] CalendarServer/branches/users/sagen/request-socket</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14749">14749</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-05-04 20:35:07 -0700 (Mon, 04 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Starting work on unix domain socket file support for requests</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenrequestsocketcalendarservertapcaldavpy">CalendarServer/branches/users/sagen/request-socket/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenrequestsocketrequirementsstabletxt">CalendarServer/branches/users/sagen/request-socket/requirements-stable.txt</a></li>
<li><a href="#CalendarServerbranchesuserssagenrequestsockettwistedcaldavstdconfigpy">CalendarServer/branches/users/sagen/request-socket/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenrequestsockettxweb2channelhttppy">CalendarServer/branches/users/sagen/request-socket/txweb2/channel/http.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenrequestsockettxweb2metafdpy">CalendarServer/branches/users/sagen/request-socket/txweb2/metafd.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenrequestsocketcalendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/request-socket/calendarserver/tap/caldav.py (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/request-socket/calendarserver/tap/caldav.py        2015-05-05 03:33:50 UTC (rev 14748)
+++ CalendarServer/branches/users/sagen/request-socket/calendarserver/tap/caldav.py        2015-05-05 03:35:07 UTC (rev 14749)
</span><span class="lines">@@ -1112,17 +1112,20 @@
</span><span class="cx">             # Inherit a single socket to receive accept()ed connections via
</span><span class="cx">             # recvmsg() and SCM_RIGHTS.
</span><span class="cx"> 
</span><del>-            try:
-                contextFactory = self.createContextFactory()
-            except SSLError, e:
-                self.log.error(
-                    &quot;Unable to set up SSL context factory: {error}&quot;,
-                    error=e
-                )
-                # None is okay as a context factory for ReportingHTTPService as
-                # long as we will never receive a file descriptor with the
-                # 'SSL' tag on it, since that's the only time it's used.
</del><ins>+            if config.RequestSocket:
</ins><span class="cx">                 contextFactory = None
</span><ins>+            else:
+                try:
+                    contextFactory = self.createContextFactory()
+                except SSLError, e:
+                    self.log.error(
+                        &quot;Unable to set up SSL context factory: {error}&quot;,
+                        error=e
+                    )
+                    # None is okay as a context factory for ReportingHTTPService as
+                    # long as we will never receive a file descriptor with the
+                    # 'SSL' tag on it, since that's the only time it's used.
+                    contextFactory = None
</ins><span class="cx"> 
</span><span class="cx">             ReportingHTTPService(
</span><span class="cx">                 requestFactory, int(config.MetaFD), contextFactory
</span><span class="lines">@@ -1750,41 +1753,47 @@
</span><span class="cx">             s._inheritedSockets = []
</span><span class="cx">             dispatcher = None
</span><span class="cx"> 
</span><del>-        for bindAddress in self._allBindAddresses():
-            self._validatePortConfig()
-            if config.UseMetaFD:
-                portsList = [(config.BindHTTPPorts, &quot;TCP&quot;)]
-                if config.EnableSSL:
-                    portsList.append((config.BindSSLPorts, &quot;SSL&quot;))
-                for ports, description in portsList:
-                    for port in ports:
-                        cl.addPortService(
-                            description, port, bindAddress,
-                            config.ListenBacklog
</del><ins>+        if config.RequestSocket:
+            cl.addSocketFileService(
+                &quot;TCP&quot;, config.RequestSocket, config.ListenBacklog
+            )
+
+        else:
+            for bindAddress in self._allBindAddresses():
+                self._validatePortConfig()
+                if config.UseMetaFD:
+                    portsList = [(config.BindHTTPPorts, &quot;TCP&quot;)]
+                    if config.EnableSSL:
+                        portsList.append((config.BindSSLPorts, &quot;SSL&quot;))
+                    for ports, description in portsList:
+                        for port in ports:
+                            cl.addPortService(
+                                description, port, bindAddress,
+                                config.ListenBacklog
+                            )
+                else:
+                    def _openSocket(addr, port):
+                        log.info(
+                            &quot;Opening socket for inheritance at {address}:{port}&quot;,
+                            address=addr, port=port
</ins><span class="cx">                         )
</span><del>-            else:
-                def _openSocket(addr, port):
-                    log.info(
-                        &quot;Opening socket for inheritance at {address}:{port}&quot;,
-                        address=addr, port=port
-                    )
-                    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-                    sock.setblocking(0)
-                    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
-                    sock.bind((addr, port))
-                    sock.listen(config.ListenBacklog)
-                    s._inheritedSockets.append(sock)
-                    return sock
</del><ins>+                        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                        sock.setblocking(0)
+                        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+                        sock.bind((addr, port))
+                        sock.listen(config.ListenBacklog)
+                        s._inheritedSockets.append(sock)
+                        return sock
</ins><span class="cx"> 
</span><del>-                for portNum in config.BindHTTPPorts:
-                    sock = _openSocket(bindAddress, int(portNum))
-                    inheritFDs.append(sock.fileno())
-
-                if config.EnableSSL:
-                    for portNum in config.BindSSLPorts:
</del><ins>+                    for portNum in config.BindHTTPPorts:
</ins><span class="cx">                         sock = _openSocket(bindAddress, int(portNum))
</span><del>-                        inheritSSLFDs.append(sock.fileno())
</del><ins>+                        inheritFDs.append(sock.fileno())
</ins><span class="cx"> 
</span><ins>+                    if config.EnableSSL:
+                        for portNum in config.BindSSLPorts:
+                            sock = _openSocket(bindAddress, int(portNum))
+                            inheritSSLFDs.append(sock.fileno())
+
</ins><span class="cx">         # Start listening on the stats socket, for administrators to inspect
</span><span class="cx">         # the current stats on the server.
</span><span class="cx">         stats = None
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenrequestsocketrequirementsstabletxt"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/request-socket/requirements-stable.txt (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/request-socket/requirements-stable.txt        2015-05-05 03:33:50 UTC (rev 14748)
+++ CalendarServer/branches/users/sagen/request-socket/requirements-stable.txt        2015-05-05 03:35:07 UTC (rev 14749)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx">             #pyOpenSSL
</span><span class="cx">         pycrypto==2.6.1
</span><span class="cx"> 
</span><del>-    --editable svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14741#egg=twextpy
</del><ins>+    --editable svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@14748#egg=twextpy
</ins><span class="cx">         cffi==0.8.6
</span><span class="cx">             pycparser==2.10
</span><span class="cx">         #twisted
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenrequestsockettwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/request-socket/twistedcaldav/stdconfig.py (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/request-socket/twistedcaldav/stdconfig.py        2015-05-05 03:33:50 UTC (rev 14748)
+++ CalendarServer/branches/users/sagen/request-socket/twistedcaldav/stdconfig.py        2015-05-05 03:35:07 UTC (rev 14749)
</span><span class="lines">@@ -173,6 +173,9 @@
</span><span class="cx">     #
</span><span class="cx">     #    This configures the actual network address that the server binds to.
</span><span class="cx">     #
</span><ins>+
+    &quot;RequestSocket&quot;: &quot;caldavd_requests.sock&quot;,
+
</ins><span class="cx">     &quot;BindAddresses&quot;: [], # List of IP addresses to bind to [empty = all]
</span><span class="cx">     &quot;BindHTTPPorts&quot;: [], # List of port numbers to bind to for HTTP
</span><span class="cx">                          # [empty = same as &quot;Port&quot;]
</span><span class="lines">@@ -1213,6 +1216,7 @@
</span><span class="cx">     (&quot;RunRoot&quot;, &quot;PIDFile&quot;),
</span><span class="cx">     (&quot;RunRoot&quot;, (&quot;Stats&quot;, &quot;UnixStatsSocket&quot;,)),
</span><span class="cx">     (&quot;RunRoot&quot;, &quot;ControlSocket&quot;),
</span><ins>+    (&quot;RunRoot&quot;, &quot;RequestSocket&quot;),
</ins><span class="cx">     (&quot;RunRoot&quot;, (&quot;Memcached&quot;, &quot;Pools&quot;, &quot;Default&quot;, &quot;MemcacheSocket&quot;)),
</span><span class="cx">     (&quot;RunRoot&quot;, (&quot;DirectoryProxy&quot;, &quot;SocketPath&quot;,)),
</span><span class="cx"> ]
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenrequestsockettxweb2channelhttppy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/request-socket/txweb2/channel/http.py (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/request-socket/txweb2/channel/http.py        2015-05-05 03:33:50 UTC (rev 14748)
+++ CalendarServer/branches/users/sagen/request-socket/txweb2/channel/http.py        2015-05-05 03:35:07 UTC (rev 14749)
</span><span class="lines">@@ -116,7 +116,7 @@
</span><span class="cx">     if hostname is None:
</span><span class="cx">         try:
</span><span class="cx">             hostname = socket.gethostbyaddr(hostaddr)[0]
</span><del>-        except socket.herror:
</del><ins>+        except (socket.herror, socket.gaierror):
</ins><span class="cx">             hostname = hostaddr
</span><span class="cx">         _cachedHostNames[hostaddr] = hostname
</span><span class="cx">     return hostname
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenrequestsockettxweb2metafdpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/request-socket/txweb2/metafd.py (14748 => 14749)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/request-socket/txweb2/metafd.py        2015-05-05 03:33:50 UTC (rev 14748)
+++ CalendarServer/branches/users/sagen/request-socket/txweb2/metafd.py        2015-05-05 03:35:07 UTC (rev 14749)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> from twisted.python.util import FancyStrMixin
</span><span class="cx"> from twisted.internet.tcp import Server
</span><span class="cx"> from twext.internet.sendfdport import IStatusWatcher
</span><ins>+from twext.internet.socketfile import MaxAcceptSocketFileServer
</ins><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="lines">@@ -112,6 +113,7 @@
</span><span class="cx">         Create a TCP transport, from a socket object passed by the parent.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self._connectionCount += 1
</span><ins>+        print(&quot;XYZZY create transport&quot;, peer)
</ins><span class="cx">         transport = Server(skt, protocol, peer, JustEnoughLikeAPort,
</span><span class="cx">                            self._connectionCount, reactor)
</span><span class="cx">         if data == 'SSL':
</span><span class="lines">@@ -345,6 +347,14 @@
</span><span class="cx">         ).setServiceParent(self)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def addSocketFileService(self, description, address, backlog=None):
+        lipf = LimitingInheritingProtocolFactory(self, description)
+        self.factories.append(lipf)
+        MaxAcceptSocketFileServer(
+            lipf, address, backlog=backlog
+        ).setServiceParent(self)
+
+
</ins><span class="cx">     # IStatusWatcher
</span><span class="cx"> 
</span><span class="cx">     def initialStatus(self):
</span></span></pre>
</div>
</div>

</body>
</html>