Rev 10: Hack in a fix to avahi to work with 0.18, run server hooks and thus play nice. in http://people.ubuntu.com/~robertc/baz2.0/plugins/avahi/trunk

Robert Collins robertc at robertcollins.net
Thu Jul 5 08:48:53 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/plugins/avahi/trunk

------------------------------------------------------------
revno: 10
revision-id: robertc at robertcollins.net-20070705074852-a2qqmkb8j2he7l1c
parent: jelmer at samba.org-20070517103226-ka58k71fc58i7b16
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Thu 2007-07-05 17:48:52 +1000
message:
  Hack in a fix to avahi to work with 0.18, run server hooks and thus play nice.
modified:
  share.py                       share.py-20070323082617-ua0xkev3o590n4rm-1
=== modified file 'share.py'
--- a/share.py	2007-05-17 10:32:26 +0000
+++ b/share.py	2007-07-05 07:48:52 +0000
@@ -22,10 +22,13 @@
 import avahi
 import dbus
 import dbus.mainloop.glib
+import errno
 import gobject
 
 from bzrlib import bzrdir, errors, trace, urlutils
-from bzrlib.transport import get_transport, smart
+from bzrlib.smart import server
+from bzrlib.transport import get_transport
+from bzrlib.transport.chroot import ChrootServer
 
 
 class AdvertisedBranch:
@@ -116,6 +119,15 @@
         self.main.run()
 
     def close(self):
+        # copied from bzrlib.smart.server as its not factored well enough
+        # to reuse yet. FIX THAT - rbc 20070705
+        backing_urls = [self.smart_server.backing_transport.base]
+        try:
+            backing_urls.append(self.smart_server.backing_transport.external_url())
+        except errors.InProcessTransport:
+            pass
+        for hook in server.SmartTCPServer.hooks['server_stopped']:
+            hook(backing_urls, self.smart_server.get_url())
         for branch in self.branches:
             branch.close()
 
@@ -153,17 +165,41 @@
         The listening socket is hooked up to the main loop.
         """
         transport = get_transport('readonly+' + self.base)
-        self.smart_server = smart.SmartTCPServer(transport,
-                                                 self.host, self.port)
+        chroot_server = ChrootServer(transport)
+        chroot_server.setUp()
+        backing_transport = get_transport(chroot_server.get_url())
+        self.smart_server = server.SmartTCPServer(
+            backing_transport, self.host, self.port)
         self.port = self.smart_server.port
         gobject.io_add_watch(self.smart_server._server_socket.fileno(),
                              gobject.IO_IN, self.acceptConnection)
+        # copied from bzrlib.smart.server as its not factored well enough
+        # to reuse yet. FIX THAT - rbc 20070705
+        backing_urls = [self.smart_server.backing_transport.base]
+        try:
+            backing_urls.append(self.smart_server.backing_transport.external_url())
+        except errors.InProcessTransport:
+            pass
+        for hook in server.SmartTCPServer.hooks['server_started']:
+            hook(backing_urls, self.smart_server.get_url())
 
     def acceptConnection(self, fp, condition):
         """Accept and serve a smart server connection."""
         if condition & gobject.IO_IN:
             trace.mutter('Accepting smart server connection')
-            self.smart_server.accept_and_serve()
+            try:
+                conn, client_addr = self.smart_server._server_socket.accept()
+            except self.smart_server._socket_timeout:
+                # just check if we're asked to stop
+                pass
+            except self.smart_server._socket_error, e:
+                # if the socket is closed by stop_background_thread
+                # we might get a EBADF here, any other socket errors
+                # should get logged.
+                if e.args[0] != errno.EBADF:
+                    trace.warning("listening socket error: %s", e)
+            else:
+                self.smart_server.serve_conn(conn)
         return True
 
     def advertiseBranches(self):



More information about the bazaar-commits mailing list