]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
Changing socket
authoraguerre <aguerre>
Fri, 4 Oct 2013 12:27:55 +0000 (12:27 +0000)
committeraguerre <aguerre>
Fri, 4 Oct 2013 12:27:55 +0000 (12:27 +0000)
bin/PortManager.py
bin/searchFreePort.py

index cd9664b51cabe3d5769a95dea6211deb8a57b748..da1e06cd6732fa1c9e5ab4d12004e96512feae66 100644 (file)
@@ -43,7 +43,6 @@ if sys.platform == 'win32':
   import multiprocessing.reduction    # make sockets pickable/inheritable
 
 multiprocessing.freeze_support() # Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable.
-#ignore = multiprocessing.active_children()      # cleanup any old processes
 
 """
 This class handles port distribution for SALOME sessions.
@@ -189,6 +188,7 @@ class _ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
 class _ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
     pass
 
+pm_address = ('127.0.0.1', 51843)
 def __getServer(address):
   SocketServer.ThreadingTCPServer.allow_reuse_address = True # can be restarted immediately
   server = _ThreadedTCPServer(address, _ThreadedTCPRequestHandler, False) # Do not automatically bind
@@ -196,13 +196,13 @@ def __getServer(address):
   return server
 #
 
-pm_address = ('localhost', 12345)
 def __startServer():
+  global pm_address
   try:
     server = __getServer(pm_address)
     server.server_bind()     # Manually bind, to support allow_reuse_address
     server.server_activate()
-    address = server.server_address
+    pm_address = server.server_address
 
     # Start a thread with the server -- that thread will then start one
     # more thread for each request
@@ -211,7 +211,7 @@ def __startServer():
     #server_thread.setDaemon(True)
     server_thread.start()
     #print "Server loop running in thread:", server_thread.getName()
-    #print "Server address:", address
+    #print "Server address:", pm_address
     #return address
   except:
     #print "Server already started"
@@ -223,6 +223,7 @@ def __startServer():
 def __newClient(address, message):
   try:
     sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    #print "connect client to", address
     sock.connect(address)
     _send(sock, message)
     response = _receive(sock)
@@ -257,6 +258,3 @@ def stopServer():
 
 # Auto start: unique instance ; no effect if called multiple times
 __startServer()
-#server_thread = threading.Thread(target=__startServer, name="SALOME_PortManager")
-#server_thread.setDaemon(True)
-#server_thread.start()
index 4b5d0ca198746f29bd3dd0bd91074a9c7a55f184..bda4863c023384154cd89ec259697d4b4eb93498 100644 (file)
@@ -70,19 +70,12 @@ def searchFreePort(args={}, save_config=1, use_port=None):
   Returns first found free port number.
   """
 
-  #import PortManager
-  #client = PortManager.start_client() # :NOTE: might specify a (remote) IP
-  #portManager = client.PortManager()
   from PortManager import getPort
   port = getPort(use_port)
 
-  #PortManager.getPort()
-  #PortManager.test_value()
-
   if use_port:
     print "Check if port can be used: %d" % use_port,
-    #if not portManager.isPortUsed(use_port):
-    if port == use_port:
+    if port == use_port and port != -1:
       print "- OK"
       __setup_config(use_port, args, save_config)
       return
@@ -91,8 +84,12 @@ def searchFreePort(args={}, save_config=1, use_port=None):
       pass
   #
   print "Searching for a free port for naming service:",
-  #port = portManager.getPort()
-  print "%s - OK"%(port)
-  __setup_config(port, args, save_config)
-  #port = portManager.releasePort(port)
+  if port == -1: # try again
+    port = getPort(use_port)
+
+  if port != -1:
+    print "%s - OK"%(port)
+    __setup_config(port, args, save_config)
+  else:
+    print "Unable to obtain port"
 #