[CalendarServer-changes] [5389] CalendarServer/branches/users/glyph/sendfdport/twext/python

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 24 08:40:14 PDT 2010


Revision: 5389
          http://trac.macosforge.org/projects/calendarserver/changeset/5389
Author:   glyph at apple.com
Date:     2010-03-24 08:40:14 -0700 (Wed, 24 Mar 2010)
Log Message:
-----------
add a 'description' to allow some data to be sent along with the FD as it is transmitted so that the other end of the connection can know what to do with it

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/sendfdport/twext/python/sendfd.py
    CalendarServer/branches/users/glyph/sendfdport/twext/python/test/pullpipe.py
    CalendarServer/branches/users/glyph/sendfdport/twext/python/test/test_sendmsg.py

Modified: CalendarServer/branches/users/glyph/sendfdport/twext/python/sendfd.py
===================================================================
--- CalendarServer/branches/users/glyph/sendfdport/twext/python/sendfd.py	2010-03-24 15:30:45 UTC (rev 5388)
+++ CalendarServer/branches/users/glyph/sendfdport/twext/python/sendfd.py	2010-03-24 15:40:14 UTC (rev 5389)
@@ -20,7 +20,7 @@
 
 from twext.python.sendmsg import sendmsg, recvmsg, SCM_RIGHTS
 
-def sendfd(socketfd, fd):
+def sendfd(socketfd, fd, description):
     """
     Send the given FD to another process via L{sendmsg} on the given C{AF_UNIX}
     socket.
@@ -33,9 +33,14 @@
     @param fd: A file descriptor to be sent to the other process.
 
     @type fd: C{int}
+
+    @param description: a string describing the socket that was passed.
+
+    @type description: C{str}
     """
-    args = (socketfd, "", 0, [(SOL_SOCKET, SCM_RIGHTS, pack("i", fd))])
-    sendmsg(*args)
+    sendmsg(
+        socketfd, description, 0, [(SOL_SOCKET, SCM_RIGHTS, pack("i", fd))]
+    )
 
 
 def recvfd(socketfd):
@@ -48,9 +53,9 @@
 
     @param fd: C{int}
 
-    @return: a new file descriptor.
+    @return: a 2-tuple of (new file descriptor, description).
 
-    @rtype: C{int}
+    @rtype: 2-tuple of (C{int}, C{str})
     """
     data, flags, ancillary = recvmsg(socketfd)
     [(cmsg_level, cmsg_type, packedFD)] = ancillary
@@ -58,4 +63,4 @@
     # since those are the *only* standard values, there's not much point in
     # checking.
     [unpackedFD] = unpack("i", packedFD)
-    return unpackedFD
+    return (unpackedFD, data)

Modified: CalendarServer/branches/users/glyph/sendfdport/twext/python/test/pullpipe.py
===================================================================
--- CalendarServer/branches/users/glyph/sendfdport/twext/python/test/pullpipe.py	2010-03-24 15:30:45 UTC (rev 5388)
+++ CalendarServer/branches/users/glyph/sendfdport/twext/python/test/pullpipe.py	2010-03-24 15:40:14 UTC (rev 5389)
@@ -19,8 +19,8 @@
 if __name__ == '__main__':
     from twext.python.sendfd import recvfd
     import sys, os
-    fd = recvfd(int(sys.argv[1]))
-    os.write(fd, "Test fixture data.\n")
+    fd, description = recvfd(int(sys.argv[1]))
+    os.write(fd, "Test fixture data: %s.\n" % (description,))
     os.close(fd)
 
     

Modified: CalendarServer/branches/users/glyph/sendfdport/twext/python/test/test_sendmsg.py
===================================================================
--- CalendarServer/branches/users/glyph/sendfdport/twext/python/test/test_sendmsg.py	2010-03-24 15:30:45 UTC (rev 5388)
+++ CalendarServer/branches/users/glyph/sendfdport/twext/python/test/test_sendmsg.py	2010-03-24 15:40:14 UTC (rev 5389)
@@ -154,7 +154,7 @@
     @inlineCallbacks
     def test_sendSubProcessFD(self):
         """
-        Calling L{sendsmsg} with SOL_SOCKET, SCM_RIGHTS , and a platform-endian
+        Calling L{sendsmsg} with SOL_SOCKET, SCM_RIGHTS, and a platform-endian
         packed file descriptor number should send that file descriptor to a
         different process, where it can be retrieved by using L{recvmsg}.
         """
@@ -163,10 +163,10 @@
         yield sspp.started
         pipeOut, pipeIn = pipe()
         self.addCleanup(close, pipeOut)
-        sendfd(self.input.fileno(), pipeIn)
+        sendfd(self.input.fileno(), pipeIn, "blonk")
         close(pipeIn)
         yield sspp.stopped
-        self.assertEquals(read(pipeOut, 1024), "Test fixture data.\n")
+        self.assertEquals(read(pipeOut, 1024), "Test fixture data: blonk.\n")
         # Make sure that the pipe is actually closed now.
         self.assertEquals(read(pipeOut, 1024), "")
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100324/ffc7317a/attachment.html>


More information about the calendarserver-changes mailing list