diff mercurial/hgweb/server.py @ 6262:de7256c82fad

hgweb: clarify which address and port can/cannot be bound at startup (bug 769) The error message at startup when the address/port could not be bound was confusing: hg serve abort: cannot start server: Address already in use Be more explicit: $ hg serve -a localhost abort: cannot start server at 'localhost:8000': Address already in use Also be more explicit on success, showing hostname and ip address/port: $ hg -v serve -a localhost -p 80 listening at http://localhost/ (127.0.0.1:80) We are careful to handle a missconfigured machine whose hostname does not resolve, falling back to the address given at the command line. Remove a dead-code error message.
author Stephen Deasey <sdeasey@gmail.com>
date Mon, 10 Mar 2008 19:25:34 +0000
parents fe8dbbe9520d
children f615ece5fec3
line wrap: on
line diff
--- a/mercurial/hgweb/server.py	Fri Mar 14 22:12:50 2008 +0100
+++ b/mercurial/hgweb/server.py	Mon Mar 10 19:25:34 2008 +0000
@@ -253,13 +253,6 @@
                 return hgwebobj
             self.application = make_handler()
 
-            addr = address
-            if addr in ('', '::'):
-                addr = socket.gethostname()
-
-            self.addr, self.port = addr, port
-            self.prefix = prefix
-
             if ssl_cert:
                 try:
                     from OpenSSL import SSL
@@ -273,6 +266,15 @@
                 self.server_bind()
                 self.server_activate()
 
+            self.addr, self.port = self.socket.getsockname()[0:2]
+            self.prefix = prefix
+
+            self.fqaddr = socket.getfqdn(address)
+            try:
+                socket.getaddrbyhost(self.fqaddr)
+            except:
+                fqaddr = address
+
     class IPv6HTTPServer(MercurialHTTPServer):
         address_family = getattr(socket, 'AF_INET6', None)
 
@@ -292,4 +294,5 @@
         else:
             return MercurialHTTPServer((address, port), handler)
     except socket.error, inst:
-        raise util.Abort(_('cannot start server: %s') % inst.args[1])
+        raise util.Abort(_("cannot start server at '%s:%d': %s")
+                         % (address, port, inst.args[1]))