ia64/xen-unstable

changeset 7944:508bc376c1dd

Remove whole piles of cruft from the connection layer. The only thing that was
using connectionMade, connectionLost, startedConnecting, clientConnectionLost,
and clientConnectionFailed was the test classes (TestClientFactory,
TestClientProtocol, TestServerFactory, TestServerProtocol), so they were
actually testing lots of code that no-one else was using. All these classes
have gone, freeing up lots of cruft around.

The useless classes Factory, ServerFactory, ClientFactory, RelocationFactory,
UnixServerConnection, and TCPServerConnection have gone, in favour of passing
the Protocol class directly to SocketListener, and using SocketServerConnection
directly.

connectTransport has gone, in favour of overriding connect directly.

Piles of closedown cruft has gone, as this was only supporting the correct
output of connectionLost events, none of which we need.

Unused SocketServerConnection.{getHost,getPeer} have gone.

Mark some parameters in relocate as unused.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Mon Nov 21 12:55:51 2005 +0100 (2005-11-21)
parents 3a544c04cc61
children 4f7b4ca2e30c
files tools/python/xen/web/connection.py tools/python/xen/web/protocol.py tools/python/xen/web/tcp.py tools/python/xen/web/unix.py tools/python/xen/xend/server/relocate.py
line diff
     1.1 --- a/tools/python/xen/web/connection.py	Mon Nov 21 12:44:43 2005 +0100
     1.2 +++ b/tools/python/xen/web/connection.py	Mon Nov 21 12:55:51 2005 +0100
     1.3 @@ -14,6 +14,7 @@
     1.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     1.5  #============================================================================
     1.6  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     1.7 +# Copyright (C) 2005 XenSource Ltd.
     1.8  #============================================================================
     1.9  
    1.10  import sys
    1.11 @@ -46,13 +47,10 @@ class SocketServerConnection:
    1.12          self.server = server
    1.13          self.buffer_n = 1024
    1.14          self.thread = None
    1.15 -        self.connected = True
    1.16 -        protocol.setTransport(self)
    1.17 -        protocol.connectionMade(addr)
    1.18 +        self.protocol.setTransport(self)
    1.19  
    1.20      def run(self):
    1.21          self.thread = threading.Thread(target=self.main)
    1.22 -        #self.thread.setDaemon(True)
    1.23          self.thread.start()
    1.24  
    1.25      def main(self):
    1.26 @@ -91,10 +89,6 @@ class SocketServerConnection:
    1.27                  return True
    1.28  
    1.29      def dataReceived(self, data):
    1.30 -        if not self.connected:
    1.31 -            return True
    1.32 -        if not self.protocol:
    1.33 -            return True
    1.34          try:
    1.35              self.protocol.dataReceived(data)
    1.36          except SystemExit:
    1.37 @@ -110,7 +104,6 @@ class SocketServerConnection:
    1.38      def loseConnection(self, reason=None):
    1.39          self.thread = None
    1.40          self.closeSocket(reason)
    1.41 -        self.closeProtocol(reason)
    1.42  
    1.43      def closeSocket(self, reason):
    1.44          try:
    1.45 @@ -120,32 +113,15 @@ class SocketServerConnection:
    1.46          except:
    1.47              pass
    1.48  
    1.49 -    def closeProtocol(self, reason):
    1.50 -        try:
    1.51 -            if self.connected:
    1.52 -                self.connected = False
    1.53 -                if self.protocol:
    1.54 -                    self.protocol.connectionLost(reason)
    1.55 -        except SystemExit:
    1.56 -            raise
    1.57 -        except:
    1.58 -            pass
    1.59 -
    1.60 -    def getHost(self):
    1.61 -        return self.sock.getsockname()
    1.62 -
    1.63 -    def getPeer(self):
    1.64 -        return self.addr
    1.65 -
    1.66  class SocketListener:
    1.67      """A server socket, running listen in a thread.
    1.68      Accepts connections and runs a thread for each one.
    1.69      """
    1.70  
    1.71 -    def __init__(self, factory, backlog=None):
    1.72 +    def __init__(self, protocol_class, backlog=None):
    1.73          if backlog is None:
    1.74              backlog = 5
    1.75 -        self.factory = factory
    1.76 +        self.protocol_class = protocol_class
    1.77          self.sock = None
    1.78          self.backlog = backlog
    1.79          self.thread = None
    1.80 @@ -171,9 +147,7 @@ class SocketListener:
    1.81          self.loseConnection(reason)
    1.82  
    1.83      def run(self):
    1.84 -        self.factory.doStart()
    1.85          self.thread = threading.Thread(target=self.main)
    1.86 -        #self.thread.setDaemon(True)
    1.87          self.thread.start()
    1.88  
    1.89      def main(self):
    1.90 @@ -206,18 +180,12 @@ class SocketListener:
    1.91                  return True
    1.92  
    1.93      def accepted(self, sock, addr):
    1.94 -        protocol = self.factory.buildProtocol(addr)
    1.95 -        if protocol is None:
    1.96 -            self.loseConnection()
    1.97 -            return True
    1.98 -        connection = self.acceptConnection(sock, protocol, addr)
    1.99 -        connection.run()
   1.100 +        self.acceptConnection(sock, self.protocol_class(), addr).run()
   1.101          return False
   1.102  
   1.103      def loseConnection(self, reason=None):
   1.104          self.thread = None
   1.105          self.closeSocket(reason)
   1.106 -        self.closeFactory(reason)
   1.107  
   1.108      def closeSocket(self, reason):
   1.109          try:
   1.110 @@ -227,13 +195,6 @@ class SocketListener:
   1.111          except Exception, ex:
   1.112              pass
   1.113  
   1.114 -    def closeFactory(self, reason):
   1.115 -        try:
   1.116 -            self.factory.doStop()
   1.117 -        except SystemExit:
   1.118 -            raise
   1.119 -        except:
   1.120 -            pass
   1.121  
   1.122  class SocketClientConnection:
   1.123      """A connection to a server from a client.
   1.124 @@ -246,7 +207,6 @@ class SocketClientConnection:
   1.125          self.addr = None
   1.126          self.connector = connector
   1.127          self.buffer_n = 1024
   1.128 -        self.connected = False
   1.129  
   1.130      def createSocket (self):
   1.131          raise NotImplementedError()
   1.132 @@ -263,8 +223,7 @@ class SocketClientConnection:
   1.133              sock = self.createSocket()
   1.134              sock.connect(self.addr)
   1.135              self.sock = sock
   1.136 -            self.connected = True
   1.137 -            self.protocol = self.connector.buildProtocol(self.addr)
   1.138 +            self.protocol = self.connector.protocol_class()
   1.139              self.protocol.setTransport(self)
   1.140          except SystemExit:
   1.141              raise
   1.142 @@ -335,8 +294,6 @@ class SocketClientConnection:
   1.143      def loseConnection(self, reason=None):
   1.144          self.thread = None
   1.145          self.closeSocket(reason)
   1.146 -        self.closeProtocol(reason)
   1.147 -        self.closeConnector(reason)
   1.148  
   1.149      def closeSocket(self, reason):
   1.150          try:
   1.151 @@ -347,71 +304,14 @@ class SocketClientConnection:
   1.152          except:
   1.153              pass
   1.154  
   1.155 -    def closeProtocol(self, reason):
   1.156 -        try:
   1.157 -            if self.connected:
   1.158 -                self.connected = False
   1.159 -                if self.protocol:
   1.160 -                    self.protocol.connectionLost(reason)
   1.161 -        except SystemExit:
   1.162 -            raise
   1.163 -        except:
   1.164 -            pass
   1.165 -        self.protocol = None
   1.166 -
   1.167 -    def closeConnector(self, reason):
   1.168 -        try:
   1.169 -            self.connector.connectionLost(reason)
   1.170 -        except SystemExit:
   1.171 -            raise
   1.172 -        except:
   1.173 -            pass
   1.174 -        
   1.175  class SocketConnector:
   1.176      """A client socket. Connects to a server and runs the client protocol
   1.177      in a thread.
   1.178      """
   1.179  
   1.180 -    def __init__(self, factory):
   1.181 -        self.factoryStarted = False
   1.182 -        self.clientLost = False
   1.183 -        self.clientFailed = False
   1.184 -        self.factory = factory
   1.185 -        self.state = "disconnected"
   1.186 +    def __init__(self, protocol_class):
   1.187 +        self.protocol_class = protocol_class
   1.188          self.transport = None
   1.189  
   1.190 -    def connectTransport(self):
   1.191 -        raise NotImplementedError()
   1.192 -
   1.193      def connect(self):
   1.194 -        if self.state != "disconnected":
   1.195 -            raise socket.error(EINVAL, "cannot connect in state " + self.state)
   1.196 -        self.state = "connecting"
   1.197 -        self.clientLost = False
   1.198 -        self.clientFailed = False
   1.199 -        if not self.factoryStarted:
   1.200 -            self.factoryStarted = True
   1.201 -            self.factory.doStart()
   1.202 -        self.factory.startedConnecting(self)
   1.203 -        self.connectTransport()
   1.204 -        self.state = "connected"
   1.205 -
   1.206 -    def stopConnecting(self):
   1.207 -        if self.state != "connecting":
   1.208 -            return
   1.209 -        self.state = "disconnected"
   1.210 -        self.transport.disconnect()
   1.211 -
   1.212 -    def buildProtocol(self, addr):
   1.213 -        return self.factory.buildProtocol(addr)
   1.214 -
   1.215 -    def connectionLost(self, reason=None):
   1.216 -        if not self.clientLost:
   1.217 -            self.clientLost = True
   1.218 -            self.factory.clientConnectionLost(self, reason)
   1.219 -
   1.220 -    def connectionFailed(self, reason=None):
   1.221 -        if not self.clientFailed:
   1.222 -            self.clientFailed = True
   1.223 -            self.factory.clientConnectionFailed(self, reason)
   1.224 -        
   1.225 +        pass
     2.1 --- a/tools/python/xen/web/protocol.py	Mon Nov 21 12:44:43 2005 +0100
     2.2 +++ b/tools/python/xen/web/protocol.py	Mon Nov 21 12:55:51 2005 +0100
     2.3 @@ -13,85 +13,19 @@
     2.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     2.5  #============================================================================
     2.6  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     2.7 +# Copyright (C) 2005 XenSource Ltd.
     2.8  #============================================================================
     2.9  
    2.10 -class Factory:
    2.11 -    """Generic protocol factory.
    2.12 -    """
    2.13 -
    2.14 -    starts = 0
    2.15 -
    2.16 -    def __init__(self):
    2.17 -        pass
    2.18 -
    2.19 -    def doStart(self):
    2.20 -        if self.starts == 0:
    2.21 -            self.startFactory()
    2.22 -        self.starts += 1
    2.23 -
    2.24 -    def doStop(self):
    2.25 -        if self.starts > 0:
    2.26 -            self.starts -= 1
    2.27 -        else:
    2.28 -            return
    2.29 -        if self.starts == 0:
    2.30 -            self.stopFactory()
    2.31 -
    2.32 -    def buildProtocol(self, addr):
    2.33 -        return Protocol(self)
    2.34 -
    2.35 -    def startFactory(self):
    2.36 -        pass
    2.37 -
    2.38 -    def stopFactory(self):
    2.39 -        pass
    2.40 -
    2.41 -class ServerFactory(Factory):
    2.42 -    """Factory for server protocols.
    2.43 -    """
    2.44 -    pass
    2.45 -    
    2.46 -class ClientFactory(Factory):
    2.47 -    """Factory for client protocols.
    2.48 -    """
    2.49 -    
    2.50 -    def startedConnecting(self, connector):
    2.51 -        pass
    2.52 -
    2.53 -    def clientConnectionLost(self, connector, reason):
    2.54 -        pass
    2.55 -
    2.56 -    def clientConnectionFailed(self, connector, reason):
    2.57 -        pass
    2.58 -
    2.59 -
    2.60  class Protocol:
    2.61  
    2.62 -    factory = None
    2.63 -    transport = None
    2.64 -    connected = False
    2.65 -
    2.66 -    def __init__(self, factory):
    2.67 -        self.factory = factory
    2.68 +    def __init__(self):
    2.69 +        self.transport = None
    2.70  
    2.71      def setTransport(self, transport):
    2.72          self.transport = transport
    2.73 -        self.connected = bool(transport)
    2.74 -
    2.75 -    def getTransport(self):
    2.76 -        return self.transport
    2.77 -
    2.78 -    def connectionMade(self, addr):
    2.79 -        print 'Protocol>connectionMade>', addr
    2.80 -        pass
    2.81 -
    2.82 -    def connectionLost(self, reason=None):
    2.83 -        print 'Protocol>connectionLost>', reason
    2.84 -        pass
    2.85  
    2.86      def dataReceived(self, data):
    2.87          print 'Protocol>dataReceived>'
    2.88 -        pass
    2.89  
    2.90      def write(self, data):
    2.91          if self.transport:
    2.92 @@ -104,40 +38,3 @@ class Protocol:
    2.93              return self.transport.read()
    2.94          else:
    2.95              return None
    2.96 -
    2.97 -class TestClientFactory(ClientFactory):
    2.98 -
    2.99 -    def buildProtocol(self, addr):
   2.100 -        print 'TestClientFactory>buildProtocol>', addr
   2.101 -        return TestClientProtocol(self)
   2.102 -    
   2.103 -    def startedConnecting(self, connector):
   2.104 -        print 'TestClientFactory>startedConnecting>', connector
   2.105 -
   2.106 -    def clientConnectionLost(self, connector, reason):
   2.107 -        print 'TestClientFactory>clientConnectionLost>', connector, reason
   2.108 -
   2.109 -    def clientConnectionFailed(self, connector, reason):
   2.110 -        print 'TestClientFactory>clientConnectionFailed>', connector, reason
   2.111 -
   2.112 -class TestClientProtocol(Protocol):
   2.113 -
   2.114 -    def connectionMade(self, addr):
   2.115 -        print 'TestClientProtocol>connectionMade>', addr
   2.116 -        self.write("hello")
   2.117 -        self.write("there")
   2.118 -
   2.119 -class TestServerFactory(Factory):
   2.120 -
   2.121 -    def buildProtocol(self, addr):
   2.122 -        print 'TestServerFactory>buildProtocol>', addr
   2.123 -        return TestServerProtocol(self)
   2.124 -    
   2.125 -class TestServerProtocol(Protocol):
   2.126 -
   2.127 -    def dataReceived(self, data):
   2.128 -        print 'TestServerProtocol>dataReceived>', len(data), data
   2.129 -        #sys.exit(0)
   2.130 -        import os
   2.131 -        os._exit(0)
   2.132 -        
     3.1 --- a/tools/python/xen/web/tcp.py	Mon Nov 21 12:44:43 2005 +0100
     3.2 +++ b/tools/python/xen/web/tcp.py	Mon Nov 21 12:55:51 2005 +0100
     3.3 @@ -24,13 +24,10 @@ import errno
     3.4  from connection import *
     3.5  from protocol import *
     3.6  
     3.7 -class TCPServerConnection(SocketServerConnection):
     3.8 -    pass
     3.9 -
    3.10  class TCPListener(SocketListener):
    3.11  
    3.12 -    def __init__(self, port, factory, backlog=None, interface=''):
    3.13 -        SocketListener.__init__(self, factory, backlog=backlog)
    3.14 +    def __init__(self, port, protocol, backlog=None, interface=''):
    3.15 +        SocketListener.__init__(self, protocol, backlog=backlog)
    3.16          self.port = port
    3.17          self.interface = interface
    3.18          
    3.19 @@ -53,7 +50,7 @@ class TCPListener(SocketListener):
    3.20                      raise
    3.21  
    3.22      def acceptConnection(self, sock, protocol, addr):
    3.23 -        return TCPServerConnection(sock, protocol, addr, self)
    3.24 +        return SocketServerConnection(sock, protocol, addr, self)
    3.25  
    3.26  class TCPClientConnection(SocketClientConnection):
    3.27  
    3.28 @@ -70,8 +67,8 @@ class TCPClientConnection(SocketClientCo
    3.29      
    3.30  class TCPConnector(SocketConnector):
    3.31  
    3.32 -    def __init__(self, host, port, factory, timeout=None, bindAddress=None):
    3.33 -        SocketConnector.__init__(self, factory)
    3.34 +    def __init__(self, host, port, protocol, timeout=None, bindAddress=None):
    3.35 +        SocketConnector.__init__(self, protocol)
    3.36          self.host = host
    3.37          self.port = self.servicePort(port)
    3.38          self.bindAddress = bindAddress
    3.39 @@ -85,33 +82,18 @@ class TCPConnector(SocketConnector):
    3.40                  raise IOError("unknown service: " + ex)
    3.41          return port
    3.42  
    3.43 -    def connectTransport(self):
    3.44 +    def connect(self):
    3.45          self.transport = TCPClientConnection(
    3.46              self.host, self.port, self.bindAddress, self)
    3.47          self.transport.connect(self.timeout)
    3.48  
    3.49 -def listenTCP(port, factory, interface='', backlog=None):
    3.50 -    l = TCPListener(port, factory, interface=interface, backlog=backlog)
    3.51 +def listenTCP(port, protocol, interface='', backlog=None):
    3.52 +    l = TCPListener(port, protocol, interface=interface, backlog=backlog)
    3.53      l.startListening()
    3.54      return l
    3.55  
    3.56 -def connectTCP(host, port, factory, timeout=None, bindAddress=None):
    3.57 -    c = TCPConnector(host, port, factory, timeout=timeout, bindAddress=bindAddress)
    3.58 +def connectTCP(host, port, protocol, timeout=None, bindAddress=None):
    3.59 +    c = TCPConnector(host, port, protocol, timeout=timeout,
    3.60 +                     bindAddress=bindAddress)
    3.61      c.connect()
    3.62      return c
    3.63 -
    3.64 -def main(argv):
    3.65 -    host = 'localhost'
    3.66 -    port = 8005
    3.67 -    if argv[1] == "client":
    3.68 -        c = connectTCP(host, port, TestClientFactory())
    3.69 -        print 'client:', c
    3.70 -    else:
    3.71 -        s = listenTCP(port, TestServerFactory())
    3.72 -        print 'server:', s
    3.73 -        
    3.74 -if __name__ == "__main__":
    3.75 -    main(sys.argv)
    3.76 -
    3.77 -        
    3.78 -
     4.1 --- a/tools/python/xen/web/unix.py	Mon Nov 21 12:44:43 2005 +0100
     4.2 +++ b/tools/python/xen/web/unix.py	Mon Nov 21 12:55:51 2005 +0100
     4.3 @@ -13,6 +13,7 @@
     4.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     4.5  #============================================================================
     4.6  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     4.7 +# Copyright (C) 2005 XenSource Ltd.
     4.8  #============================================================================
     4.9  
    4.10  import sys
    4.11 @@ -23,13 +24,10 @@ import os.path
    4.12  from connection import *
    4.13  from protocol import *
    4.14  
    4.15 -class UnixServerConnection(SocketServerConnection):
    4.16 -    pass
    4.17 -
    4.18  class UnixListener(SocketListener):
    4.19  
    4.20 -    def __init__(self, path, factory, backlog=None):
    4.21 -        SocketListener.__init__(self, factory, backlog=backlog)
    4.22 +    def __init__(self, path, protocol, backlog=None):
    4.23 +        SocketListener.__init__(self, protocol, backlog=backlog)
    4.24          self.path = path
    4.25          
    4.26      def createSocket(self):
    4.27 @@ -48,7 +46,7 @@ class UnixListener(SocketListener):
    4.28          return sock
    4.29  
    4.30      def acceptConnection(self, sock, protocol, addr):
    4.31 -        return UnixServerConnection(sock, protocol, self.path, self)
    4.32 +        return SocketServerConnection(sock, protocol, self.path, self)
    4.33  
    4.34  class UnixClientConnection(SocketClientConnection):
    4.35  
    4.36 @@ -62,34 +60,21 @@ class UnixClientConnection(SocketClientC
    4.37      
    4.38  class UnixConnector(SocketConnector):
    4.39  
    4.40 -    def __init__(self, path, factory, timeout=None):
    4.41 -        SocketConnector.__init__(self, factory)
    4.42 +    def __init__(self, path, protocol, timeout=None):
    4.43 +        SocketConnector.__init__(self, protocol)
    4.44          self.addr = path
    4.45          self.timeout = timeout
    4.46  
    4.47 -    def connectTransport(self):
    4.48 +    def connect(self):
    4.49          self.transport = UnixClientConnection(self.addr, self)
    4.50          self.transport.connect(self.timeout)
    4.51  
    4.52 -def listenUNIX(path, factory, backlog=None):
    4.53 -    l = UnixListener(path, factory, backlog=backlog)
    4.54 +def listenUNIX(path, protocol, backlog=None):
    4.55 +    l = UnixListener(path, protocol, backlog=backlog)
    4.56      l.startListening()
    4.57      return l
    4.58  
    4.59 -def connectUNIX(path, factory, timeout=None):
    4.60 -    c = UnixConnector(path, factory, timeout=timeout)
    4.61 +def connectUNIX(path, protocol, timeout=None):
    4.62 +    c = UnixConnector(path, protocol, timeout=timeout)
    4.63      c.connect()
    4.64      return c
    4.65 -
    4.66 -def main(argv):
    4.67 -    path = "/tmp/test-foo"
    4.68 -    if argv[1] == "client":
    4.69 -        c = connectUNIX(path, TestClientFactory())
    4.70 -        print "client:", c
    4.71 -    else:
    4.72 -        s = listenUNIX(path, TestServeractory())
    4.73 -        print "server:", s
    4.74 -
    4.75 -if __name__ == "__main__":
    4.76 -    main(sys.argv)
    4.77 -
     5.1 --- a/tools/python/xen/xend/server/relocate.py	Mon Nov 21 12:44:43 2005 +0100
     5.2 +++ b/tools/python/xen/xend/server/relocate.py	Mon Nov 21 12:55:51 2005 +0100
     5.3 @@ -22,7 +22,6 @@ import StringIO
     5.4  
     5.5  from xen.web import protocol, tcp, unix
     5.6  
     5.7 -from xen.xend import scheduler
     5.8  from xen.xend import sxp
     5.9  from xen.xend.XendError import XendError
    5.10  from xen.xend import XendRoot
    5.11 @@ -39,7 +38,7 @@ class RelocationProtocol(protocol.Protoc
    5.12      """
    5.13  
    5.14      def __init__(self):
    5.15 -        #protocol.Protocol.__init__(self)
    5.16 +        protocol.Protocol.__init__(self)
    5.17          self.parser = sxp.Parser()
    5.18  
    5.19      def dataReceived(self, data):
    5.20 @@ -59,11 +58,6 @@ class RelocationProtocol(protocol.Protoc
    5.21      def loseConnection(self):
    5.22          if self.transport:
    5.23              self.transport.loseConnection()
    5.24 -        if self.connected:
    5.25 -            scheduler.now(self.connectionLost)
    5.26 -
    5.27 -    def connectionLost(self, reason=None):
    5.28 -        pass
    5.29  
    5.30      def send_reply(self, sxpr):
    5.31          io = StringIO.StringIO()
    5.32 @@ -91,7 +85,7 @@ class RelocationProtocol(protocol.Protoc
    5.33      def opname(self, name):
    5.34           return 'op_' + name.replace('.', '_')
    5.35  
    5.36 -    def operror(self, name, req):
    5.37 +    def operror(self, name, _):
    5.38          raise XendError('Invalid operation: ' +name)
    5.39  
    5.40      def dispatch(self, req):
    5.41 @@ -100,7 +94,7 @@ class RelocationProtocol(protocol.Protoc
    5.42          op_method = getattr(self, op_method_name, self.operror)
    5.43          return op_method(op_name, req)
    5.44  
    5.45 -    def op_help(self, name, req):
    5.46 +    def op_help(self, _1, _2):
    5.47          def nameop(x):
    5.48              if x.startswith('op_'):
    5.49                  return x[3:].replace('_', '.')
    5.50 @@ -110,10 +104,10 @@ class RelocationProtocol(protocol.Protoc
    5.51          l = [ nameop(k) for k in dir(self) if k.startswith('op_') ]
    5.52          return l
    5.53  
    5.54 -    def op_quit(self, name, req):
    5.55 +    def op_quit(self, _1, _2):
    5.56          self.loseConnection()
    5.57  
    5.58 -    def op_receive(self, name, req):
    5.59 +    def op_receive(self, name, _):
    5.60          if self.transport:
    5.61              self.send_reply(["ready", name])
    5.62              self.transport.sock.setblocking(1)
    5.63 @@ -124,26 +118,15 @@ class RelocationProtocol(protocol.Protoc
    5.64              log.error(name + ": no transport")
    5.65              raise XendError(name + ": no transport")
    5.66  
    5.67 -class RelocationFactory(protocol.ServerFactory):
    5.68 -    """Asynchronous handler for the relocation server socket.
    5.69 -    """
    5.70 -
    5.71 -    def __init__(self):
    5.72 -        #protocol.ServerFactory.__init__(self)
    5.73 -        pass
    5.74 -
    5.75 -    def buildProtocol(self, addr):
    5.76 -        return RelocationProtocol()
    5.77  
    5.78  def listenRelocation():
    5.79 -    factory = RelocationFactory()
    5.80      if xroot.get_xend_unix_server():
    5.81          path = '/var/lib/xend/relocation-socket'
    5.82 -        unix.listenUNIX(path, factory)
    5.83 +        unix.listenUNIX(path, RelocationProtocol)
    5.84      if xroot.get_xend_relocation_server():
    5.85          port = xroot.get_xend_relocation_port()
    5.86          interface = xroot.get_xend_relocation_address()
    5.87 -        l = tcp.listenTCP(port, factory, interface=interface)
    5.88 +        l = tcp.listenTCP(port, RelocationProtocol, interface=interface)
    5.89          l.setCloExec()
    5.90  
    5.91  def setupRelocation(dst, port):