[Checkins] SVN: zc.ngi/trunk/ Bug Fixed

Jim Fulton jim at zope.com
Sat Dec 10 17:19:40 UTC 2011


Log message for revision 123663:
  Bug Fixed
    zc.ngi.async listeners didn't provide the real address when binding
    to port 0.
  

Changed:
  U   zc.ngi/trunk/README.txt
  U   zc.ngi/trunk/src/zc/ngi/async.py
  U   zc.ngi/trunk/src/zc/ngi/tests.py

-=-
Modified: zc.ngi/trunk/README.txt
===================================================================
--- zc.ngi/trunk/README.txt	2011-12-10 16:41:48 UTC (rev 123662)
+++ zc.ngi/trunk/README.txt	2011-12-10 17:19:39 UTC (rev 123663)
@@ -20,6 +20,15 @@
 *******
 
 ====================
+2.0.0 (2011-12-10)
+====================
+
+Bugs Fixed
+
+- zc.ngi.async listeners didn't provide the real address when binding
+  to port 0.
+
+====================
 2.0.0a6 (2011-05-26)
 ====================
 

Modified: zc.ngi/trunk/src/zc/ngi/async.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/async.py	2011-12-10 16:41:48 UTC (rev 123662)
+++ zc.ngi/trunk/src/zc/ngi/async.py	2011-12-10 17:19:39 UTC (rev 123663)
@@ -627,6 +627,8 @@
                     break
             else:
                 self.bind(addr)
+                if family is socket.AF_INET and addr[1] == 0:
+                    self.addr = addr = addr[0], self.socket.getsockname()[1]
 
             self.logger.info("listening on %r", addr)
             self.listen(255)

Modified: zc.ngi/trunk/src/zc/ngi/tests.py
===================================================================
--- zc.ngi/trunk/src/zc/ngi/tests.py	2011-12-10 16:41:48 UTC (rev 123662)
+++ zc.ngi/trunk/src/zc/ngi/tests.py	2011-12-10 17:19:39 UTC (rev 123663)
@@ -63,7 +63,6 @@
 def test_async_cannot_connect():
     """Let's make sure that the connector handles connection failures correctly
 
-    >>> import threading
     >>> lock = threading.Lock()
     >>> _ = lock.acquire()
 
@@ -482,7 +481,7 @@
     When creating a listener with a zc.ngi.async.Implementation, you can
     pass a thready keyword options to cause each client to get it's own thread.
 
-    >>> import functools, threading, zc.ngi.generator
+    >>> import functools
 
     >>> @functools.partial(zc.ngi.async.listener, None, thready=True)
     ... @zc.ngi.generator.handler
@@ -704,6 +703,33 @@
 
     """
 
+def async_bind_to_port_0():
+    r"""
+
+    When we bind to port 0, the listener has the actual address:
+
+    >>> def server(conn):
+    ...     conn.write('go away')
+    ...     conn.close()
+
+    >>> listener = zc.ngi.async.listener(('127.0.0.1', 0), server)
+    >>> host, port = listener.address
+    >>> host == '127.0.0.1' and port > 0
+    True
+
+    Make sure it works. :)
+
+    >>> event = threading.Event()
+
+    >>> @zc.ngi.generator.handler
+    ... def client(conn):
+    ...     print (yield)
+    ...     event.set()
+
+    >>> zc.ngi.async.connect(listener.address, client); _ = event.wait(1)
+    go away
+    """
+
 if not hasattr(socket, 'AF_UNIX'):
     # windows
     del async_peer_address_unix, async_close_unix



More information about the checkins mailing list