Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
6261:7c8101b5ceb1 | 6262:de7256c82fad |
---|---|
251 raise RepoError(_("There is no Mercurial repository here" | 251 raise RepoError(_("There is no Mercurial repository here" |
252 " (.hg not found)")) | 252 " (.hg not found)")) |
253 return hgwebobj | 253 return hgwebobj |
254 self.application = make_handler() | 254 self.application = make_handler() |
255 | 255 |
256 addr = address | |
257 if addr in ('', '::'): | |
258 addr = socket.gethostname() | |
259 | |
260 self.addr, self.port = addr, port | |
261 self.prefix = prefix | |
262 | |
263 if ssl_cert: | 256 if ssl_cert: |
264 try: | 257 try: |
265 from OpenSSL import SSL | 258 from OpenSSL import SSL |
266 ctx = SSL.Context(SSL.SSLv23_METHOD) | 259 ctx = SSL.Context(SSL.SSLv23_METHOD) |
267 except ImportError: | 260 except ImportError: |
271 sock = socket.socket(self.address_family, self.socket_type) | 264 sock = socket.socket(self.address_family, self.socket_type) |
272 self.socket = SSL.Connection(ctx, sock) | 265 self.socket = SSL.Connection(ctx, sock) |
273 self.server_bind() | 266 self.server_bind() |
274 self.server_activate() | 267 self.server_activate() |
275 | 268 |
269 self.addr, self.port = self.socket.getsockname()[0:2] | |
270 self.prefix = prefix | |
271 | |
272 self.fqaddr = socket.getfqdn(address) | |
273 try: | |
274 socket.getaddrbyhost(self.fqaddr) | |
275 except: | |
276 fqaddr = address | |
277 | |
276 class IPv6HTTPServer(MercurialHTTPServer): | 278 class IPv6HTTPServer(MercurialHTTPServer): |
277 address_family = getattr(socket, 'AF_INET6', None) | 279 address_family = getattr(socket, 'AF_INET6', None) |
278 | 280 |
279 def __init__(self, *args, **kwargs): | 281 def __init__(self, *args, **kwargs): |
280 if self.address_family is None: | 282 if self.address_family is None: |
290 if use_ipv6: | 292 if use_ipv6: |
291 return IPv6HTTPServer((address, port), handler) | 293 return IPv6HTTPServer((address, port), handler) |
292 else: | 294 else: |
293 return MercurialHTTPServer((address, port), handler) | 295 return MercurialHTTPServer((address, port), handler) |
294 except socket.error, inst: | 296 except socket.error, inst: |
295 raise util.Abort(_('cannot start server: %s') % inst.args[1]) | 297 raise util.Abort(_("cannot start server at '%s:%d': %s") |
298 % (address, port, inst.args[1])) |