WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Remove twisted from save/migrate handling.

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Remove twisted from save/migrate handling.
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Fri, 22 Apr 2005 15:30:43 +0000
Delivery-date: Fri, 13 May 2005 20:03:15 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1327.2.4, 2005/04/22 16:30:43+01:00, mjw@xxxxxxxxxxxxxxxxxxx

        Remove twisted from save/migrate handling.
        This needs to use threads, so add thread support for
        http server requests.
        
        Signed-off-by: Mike Wray <mike.wray@xxxxxx>



 web/SrvBase.py               |   98 +--------------
 web/SrvDir.py                |    3 
 web/connection.py            |   29 +++-
 web/http.py                  |   18 +-
 web/httpserver.py            |  265 ++++++++++++++++++++++++++++++++++++-------
 web/protocol.py              |   60 +++++++--
 xend/XendDomain.py           |    5 
 xend/XendMigrate.py          |  224 +++++++++++++++++++++---------------
 xend/server/SrvConsole.py    |   28 +---
 xend/server/SrvConsoleDir.py |   24 +--
 xend/server/SrvDaemon.py     |    7 -
 xend/server/SrvDmesg.py      |   22 +--
 xend/server/SrvDomain.py     |   84 ++++++-------
 xend/server/SrvDomainDir.py  |   33 ++---
 xend/server/SrvNode.py       |   36 ++---
 xend/server/SrvVnetDir.py    |   24 +--
 xend/server/SrvXendLog.py    |    5 
 xend/server/usbif.py         |    1 
 18 files changed, 556 insertions(+), 410 deletions(-)


diff -Nru a/tools/python/xen/web/SrvBase.py b/tools/python/xen/web/SrvBase.py
--- a/tools/python/xen/web/SrvBase.py   2005-05-13 16:03:51 -04:00
+++ b/tools/python/xen/web/SrvBase.py   2005-05-13 16:03:51 -04:00
@@ -2,6 +2,7 @@
 
 import types
 
+
 from xen.xend import sxp
 from xen.xend import PrettyPrint
 from xen.xend.Args import ArgError
@@ -10,6 +11,7 @@
 
 import resource
 import http
+import httpserver
 import defer
 
 def uri_pathlist(p):
@@ -29,19 +31,8 @@
 
     
     def use_sxp(self, req):
-        """Determine whether to send an SXP response to a request.
-        Uses SXP if there is no User-Agent, no Accept, or application/sxp is 
in Accept.
-
-        req            request
-        returns 1 for SXP, 0 otherwise
-        """
-        ok = 0
-        user_agent = req.getHeader('User-Agent')
-        accept = req.getHeader('Accept')
-        if (not user_agent) or (not accept) or (accept.find(sxp.mime_type) >= 
0):
-            ok = 1
-        return ok
-
+        return req.useSxp()
+    
     def get_op_method(self, op):
         """Get the method for an operation.
         For operation 'foo' looks for 'op_foo'.
@@ -60,7 +51,7 @@
 
         The method must return a list when req.use_sxp is true
         and an HTML string otherwise (or list).
-        Methods may also return a Deferred (for incomplete processing).
+        Methods may also return a ThreadRequest (for incomplete processing).
 
         req    request
         """
@@ -76,85 +67,10 @@
             req.write("Operation not implemented: " + op)
             return ''
         else:
-            return self._perform(op, op_method, req)
-
-    def _perform(self, op, op_method, req):
-        try:
-            val = op_method(op, req)
-        except Exception, err:
-            self._perform_err(err, op, req)
-            return ''
-            
-        if isinstance(val, defer.Deferred):
-            val.addCallback(self._perform_cb, op, req, dfr=1)
-            val.addErrback(self._perform_err, op, req, dfr=1)
-            return server.NOT_DONE_YET
-        else:
-            self._perform_cb(val, op, req, dfr=0)
-            return ''
-
-    def _perform_cb(self, val, op, req, dfr=0):
-        """Callback to complete the request.
-        May be called from a Deferred.
-
-        @param err: the error
-        @param req: request causing the error
-        @param dfr: deferred flag
-        """
-        if isinstance(val, resource.ErrorPage):
-            req.write(val.render(req))
-        elif self.use_sxp(req):
-            req.setHeader("Content-Type", sxp.mime_type)
-            sxp.show(val, out=req)
-        else:
-            req.write('<html><head></head><body>')
-            self.print_path(req)
-            if isinstance(val, types.ListType):
-                req.write('<code><pre>')
-                PrettyPrint.prettyprint(val, out=req)
-                req.write('</pre></code>')
-            else:
-                req.write(str(val))
-            req.write('</body></html>')
-        if dfr:
-            req.finish()
-
-    def _perform_err(self, err, op, req, dfr=0):
-        """Error callback to complete a request.
-        May be called from a Deferred.
-
-        @param err: the error
-        @param req: request causing the error
-        @param dfr: deferred flag
-        """
-        if not (isinstance(err, ArgError) or
-                  isinstance(err, sxp.ParseError) or
-                  isinstance(err, XendError)):
-            if dfr:
-                return err
-            else:
-                raise
-        #log.exception("op=%s: %s", op, str(err))
-        if self.use_sxp(req):
-            req.setHeader("Content-Type", sxp.mime_type)
-            sxp.show(['xend.err', str(err)], out=req)
-        else:
-            req.setHeader("Content-Type", "text/plain")
-            req.write('Error ')
-            req.write(': ')
-            req.write(str(err))
-        if dfr:
-            req.finish()
-        
+            return op_method(op, req)
 
     def print_path(self, req):
         """Print the path with hyperlinks.
         """
-        pathlist = [x for x in req.prepath if x != '' ]
-        s = "/"
-        req.write('<h1><a href="/">/</a>')
-        for x in pathlist:
-            s += x + "/"
-            req.write(' <a href="%s">%s</a>/' % (s, x))
-        req.write("</h1>")
+        req.printPath()
 
diff -Nru a/tools/python/xen/web/SrvDir.py b/tools/python/xen/web/SrvDir.py
--- a/tools/python/xen/web/SrvDir.py    2005-05-13 16:03:51 -04:00
+++ b/tools/python/xen/web/SrvDir.py    2005-05-13 16:03:51 -04:00
@@ -47,9 +47,6 @@
         self.table = {}
         self.order = []
 
-    def __repr__(self):
-        return "<SrvDir %x %s>" %(id(self), self.table.keys())
-
     def noChild(self, msg):
         return resource.ErrorPage(http.NOT_FOUND, msg=msg)
 
diff -Nru a/tools/python/xen/web/connection.py 
b/tools/python/xen/web/connection.py
--- a/tools/python/xen/web/connection.py        2005-05-13 16:03:51 -04:00
+++ b/tools/python/xen/web/connection.py        2005-05-13 16:03:51 -04:00
@@ -72,6 +72,8 @@
                 return True
 
     def dataReceived(self, data):
+        if not self.connected:
+            return True
         if not self.protocol:
             return True
         try:
@@ -79,7 +81,7 @@
         except SystemExit:
             raise
         except Exception, ex:
-            self.disconnect(ex)
+            self.loseConnection(ex)
             return True
         return False
 
@@ -261,7 +263,7 @@
         except SystemExit:
             raise
         except Exception, ex:
-            self.disconnect(ex)
+            self.loseConnection(ex)
 
     def mainLoop(self):
         # Something a protocol could call.
@@ -282,7 +284,7 @@
             if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                 return False
             else:
-                self.disconnect(ex)
+                self.loseConnection(ex)
                 return True
 
     def read(self):
@@ -293,7 +295,7 @@
             if ex.args[0] in (EWOULDBLOCK, EAGAIN, EINTR):
                 return None
             else:
-                self.disconnect(ex)
+                self.loseConnection(ex)
                 return True
         
     def dataReceived(self, data):
@@ -304,11 +306,11 @@
         except SystemExit:
             raise
         except Exception, ex:
-            self.disconnect(ex)
+            self.loseConnection(ex)
             return True
         return False
 
-    def disconnect(self, reason=None):
+    def loseConnection(self, reason=None):
         self.thread = None
         self.closeSocket(reason)
         self.closeProtocol(reason)
@@ -350,6 +352,8 @@
 
     def __init__(self, factory):
         self.factoryStarted = False
+        self.clientLost = False
+        self.clientFailed = False
         self.factory = factory
         self.state = "disconnected"
         self.transport = None
@@ -364,11 +368,14 @@
         if self.state != "disconnected":
             raise socket.error(EINVAL, "cannot connect in state " + self.state)
         self.state = "connecting"
+        self.clientLost = False
+        self.clientFailed = False
         if not self.factoryStarted:
             self.factoryStarted = True
             self.factory.doStart()
-        self.factory.startedConnecting()
+        self.factory.startedConnecting(self)
         self.connectTransport()
+        self.state = "connected"
 
     def stopConnecting(self):
         if self.state != "connecting":
@@ -380,8 +387,12 @@
         return self.factory.buildProtocol(addr)
 
     def connectionLost(self, reason=None):
-        self.factory.doStop()
+        if not self.clientLost:
+            self.clientLost = True
+            self.factory.clientConnectionLost(self, reason)
 
     def connectionFailed(self, reason=None):
-        self.factory.doStop()
+        if not self.clientFailed:

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Remove twisted from save/migrate handling., BitKeeper Bot <=