[Sciviews-commits] r368 - in komodo/SciViews-K-dev: components content

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 16 22:09:09 CET 2011


Author: prezez
Date: 2011-03-16 22:09:09 +0100 (Wed, 16 Mar 2011)
New Revision: 368

Modified:
   komodo/SciViews-K-dev/components/svIUtils.idl
   komodo/SciViews-K-dev/components/svUtils.py
   komodo/SciViews-K-dev/content/sessions.xul
Log:
svUtils: Closing socket server on object destruction
sessions.xul: typo corrected

Modified: komodo/SciViews-K-dev/components/svIUtils.idl
===================================================================
--- komodo/SciViews-K-dev/components/svIUtils.idl	2011-03-15 13:34:21 UTC (rev 367)
+++ komodo/SciViews-K-dev/components/svIUtils.idl	2011-03-16 21:09:09 UTC (rev 368)
@@ -60,7 +60,7 @@
 	readonly attribute wstring lastCommand;
 	readonly attribute wstring lastResult;
 	attribute wstring id;
-	readonly attribute boolean serverIsUp;
+	boolean serverIsUp();
 	wstring pushLeft(in wstring text, in string eol, in long indent, in long tabwidth);
 
     void escape();

Modified: komodo/SciViews-K-dev/components/svUtils.py
===================================================================
--- komodo/SciViews-K-dev/components/svUtils.py	2011-03-15 13:34:21 UTC (rev 367)
+++ komodo/SciViews-K-dev/components/svUtils.py	2011-03-16 21:09:09 UTC (rev 368)
@@ -63,11 +63,11 @@
 
         self.lastCommand = u''
         self.lastResult = u''
-        self.id = 'svpy'
+        self.id = 'sv'
         self.runServer = False
-        self.serverIsUp = False
         self.socketOut = ('localhost', 8888)
         self.socketIn = ('localhost', 7777)
+        self.serverConn = None
         pass
 
     class _CommandInfo:
@@ -177,8 +177,21 @@
 #    data = s.recv(1024)
 #timeout: timed out
 
+    def __del__(self):
+        try:
+            self.serverConn.close()
+        except:
+            pass
+
+    def serverIsUp(self):
+        try:
+            self.serverConn.fileno()
+            return True
+        except:
+            return False
+
     def startSocketServer(self, requestHandler):
-        if(self.serverIsUp): return -1L
+        if(self.serverIsUp()): return -1L
         self.runServer = True
         host = self.socketIn[0]
         port = self.socketIn[1]
@@ -186,52 +199,54 @@
         port_max = port + 32L
         while port < port_max:
             try:
-                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-                s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0)
-                s.settimeout(5)
+                self.serverConn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+                self.serverConn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0)
+                self.serverConn.settimeout(5)
                 log.debug('trying socket (%s, %d) ' % (host, port))
-                s.bind((host, port))
+                self.serverConn.bind((host, port))
                 break
             except Exception, e:
                 log.error(e.args)   # ERROR 10048, ERROR 98: Address already in use
-                s.close()
+                self.serverConn.close()
                 port += 1L
         if (port >= port_max): return 0L # TODO: fix this
         self.socketIn = (host, port)
         log.debug('startSocketServer: starting thread')
-        t = threading.Thread(target=self._Serve, kwargs={ \
-            's': s, 'requestHandler': requestHandler })
+        t = threading.Thread(target=self._Serve,
+                             kwargs={ 'requestHandler': requestHandler })
         t.start()
         log.debug('Serving on port %d' % port)
         self._proxiedObsSvc.notifyObservers(self._asSInt(port), 'r-server-started', None)
         return port
 
     def stopSocketServer(self):
-        if (self.runServer  != False):
-            self.runServer = False
-            log.debug('Told socket server to stop')
+        try:
+            self.serverConn.close()
+        except:
+            pass
+        self.runServer = False
+        log.debug('Told socket server to stop')
 
-    def _Serve(self, s, requestHandler):
+    def _Serve(self, requestHandler):
         # requestHandler is a Javascript object with component 'onStuff'
         # which is a function accepting one argument (string), and returning
         # a string
         requestHandlerProxy = getProxyForObject(1,
             components.interfaces.svIStuffListener,
             requestHandler, PROXY_ALWAYS | PROXY_SYNC)
-        self.serverIsUp = True
         try:
-            s.listen(1)
+            self.serverConn.listen(1)
             log.debug('Socket server listening at %d' % self.socketIn[1])
             count = 0
             connected = False
             while self.runServer:
-                while self.runServer:
+                while self.runServer and self.serverIsUp():
                     connected = False
                     try:
-                        conn, addr = s.accept()
+                        conn, addr = self.serverConn.accept()
                         connected = True
                         conn.setblocking(1)
-                        s.settimeout(10)
+                        self.serverConn.settimeout(10)
                         count += 1
                         break
                     except Exception: continue
@@ -261,8 +276,8 @@
                 log.debug('conn closed')
         except Exception, e:
             log.debug(e.args)
-        s.close()
-        self.serverIsUp = False
+        self.stopSocketServer()
+        #self.serverConn.close()
         log.debug("Exiting after %d connections" % count)
         self._proxiedObsSvc.notifyObservers(None, 'r-server-stopped', None)
         pass
@@ -341,4 +356,3 @@
     def escape(self):
         self.execInR('invisible()', 'esc')
         pass
-

Modified: komodo/SciViews-K-dev/content/sessions.xul
===================================================================
--- komodo/SciViews-K-dev/content/sessions.xul	2011-03-15 13:34:21 UTC (rev 367)
+++ komodo/SciViews-K-dev/content/sessions.xul	2011-03-16 21:09:09 UTC (rev 368)
@@ -42,7 +42,6 @@
 
 <?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
 <?xml-stylesheet href="chrome://komodo/skin/global/global.css" type="text/css"?>
-
 		<dialog id="dialog-svsetsession"
 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
 onload="OnLoad(event)"
@@ -335,7 +334,7 @@
 	if (!sv.r.running) return;
 
 	var sf = sv.tools.file;
-	var addslashes = sv.tools.strings.addslashes;
+	var addslashes = sv.tools.string.addslashes;
 	var dir = sf.path(document.getElementById("sciviews.session.dir").value);
 
 	var rDataFile = sf.path(dir, ".RData");



More information about the Sciviews-commits mailing list