From 0f2e3628de3a64291d3cb3c6f0ecd2ba6460931a Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Fri, 11 Sep 2009 13:06:45 +0000
Subject: [PATCH] Remove the need to resolve hostname to determine node
 identifier when http server explicitely listens on a non-wilcard address.
 Also, fix timerserver startup when http server listens on a non-wilcard
 address.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28957 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFActivity/ActivityTool.py                      | 9 +++++----
 product/ERP5/Tool/AlarmTool.py                           | 9 +++++----
 .../TimerService/timerserver/timerserver/TimerServer.py  | 8 +++++---
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py
index fbe4e10192..4483963149 100644
--- a/product/CMFActivity/ActivityTool.py
+++ b/product/CMFActivity/ActivityTool.py
@@ -692,16 +692,17 @@ class ActivityTool (Folder, UniqueObject):
         """ Return current node in form ip:port """
         global currentNode
         if currentNode is None:
-          port = ''
+          ip = port = ''
           from asyncore import socket_map
           for k, v in socket_map.items():
-              if hasattr(v, 'port'):
+              if hasattr(v, 'addr'):
                   # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                   type = str(getattr(v, '__class__', 'unknown'))
                   if type == 'ZServer.HTTPServer.zhttp_server':
-                      port = v.port
+                      ip, port = v.addr
                       break
-          ip = socket.gethostbyname(socket.gethostname())
+          if ip == '0.0.0.0':
+            ip = socket.gethostbyname(socket.gethostname())
           currentNode = '%s:%s' %(ip, port)
         return currentNode
         
diff --git a/product/ERP5/Tool/AlarmTool.py b/product/ERP5/Tool/AlarmTool.py
index 80ad0f4801..05bf35299b 100644
--- a/product/ERP5/Tool/AlarmTool.py
+++ b/product/ERP5/Tool/AlarmTool.py
@@ -226,16 +226,17 @@ class AlarmTool(BaseTool):
       """ Return current node in form ip:port """
       global current_node
       if current_node is None:
-        port = ''
+        ip = port = ''
         from asyncore import socket_map
         for k, v in socket_map.items():
-            if hasattr(v, 'port'):
+            if hasattr(v, 'addr'):
                 # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                 type = str(getattr(v, '__class__', 'unknown'))
                 if type == 'ZServer.HTTPServer.zhttp_server':
-                    port = v.port
+                    ip, port = v.addr
                     break
-        ip = socket.gethostbyname(socket.gethostname())
+        if ip == '0.0.0.0':
+          ip = socket.gethostbyname(socket.gethostname())
         current_node = '%s:%s' %(ip, port)
       return current_node
       
diff --git a/product/TimerService/timerserver/timerserver/TimerServer.py b/product/TimerService/timerserver/timerserver/TimerServer.py
index 8ef33b656c..40f3f543b9 100644
--- a/product/TimerService/timerserver/timerserver/TimerServer.py
+++ b/product/TimerService/timerserver/timerserver/TimerServer.py
@@ -40,19 +40,21 @@ class TimerServer:
         # wait until the zhttp_server exist in socket_map
         # because TimerService has to be started after the Zope HTTPServer
         from asyncore import socket_map
+        ip = port = ''
         while 1:
             time.sleep(5)
             for k, v in socket_map.items():
-                if hasattr(v, 'port'):
+                if hasattr(v, 'addr'):
                         # see Zope/lib/python/App/ApplicationManager.py: def getServers(self)
                         type = str(getattr(v, '__class__', 'unknown'))
                         if type == 'ZServer.HTTPServer.zhttp_server':
-                            port = v.port
+                            ip, port = v.addr
                             break
             if port:
                 break
 
-        ip = socket.gethostbyname(socket.gethostname())
+        if ip == '0.0.0.0':
+          ip = socket.gethostbyname(socket.gethostname())
 
         # To be very sure, try to connect to the HTTPServer
         # and only start after we are able to connect and got a response
-- 
2.30.9