##// END OF EJS Templates
hgweb: internalize some socket details
Matt Mackall -
r3628:dc3504af default
parent child Browse files
Show More
@@ -11,7 +11,7 b' from i18n import gettext as _'
11 11 demandload(globals(), "os re sys signal shutil imp urllib pdb shlex")
12 12 demandload(globals(), "fancyopts ui hg util lock revlog templater bundlerepo")
13 13 demandload(globals(), "difflib patch tempfile time")
14 demandload(globals(), "traceback errno socket version atexit sets bz2")
14 demandload(globals(), "traceback errno version atexit sets bz2")
15 15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
16 16
17 17 class UnknownCommand(Exception):
@@ -2531,24 +2531,14 b' def serve(ui, repo, **opts):'
2531 2531 os.read(rfd, 1)
2532 2532 os._exit(0)
2533 2533
2534 try:
2535 httpd = hgweb.server.create_server(ui, repo)
2536 except socket.error, inst:
2537 raise util.Abort(_('cannot start server: %s') % inst.args[1])
2534 httpd = hgweb.server.create_server(ui, repo)
2538 2535
2539 2536 if ui.verbose:
2540 addr, port = httpd.socket.getsockname()
2541 if addr == '0.0.0.0':
2542 addr = socket.gethostname()
2537 if httpd.port != 80:
2538 ui.status(_('listening at http://%s:%d/\n') %
2539 (httpd.addr, httpd.port))
2543 2540 else:
2544 try:
2545 addr = socket.gethostbyaddr(addr)[0]
2546 except socket.error:
2547 pass
2548 if port != 80:
2549 ui.status(_('listening at http://%s:%d/\n') % (addr, port))
2550 else:
2551 ui.status(_('listening at http://%s/\n') % addr)
2541 ui.status(_('listening at http://%s/\n') % httpd.addr)
2552 2542
2553 2543 if opts['pid_file']:
2554 2544 fp = open(opts['pid_file'], 'w')
@@ -200,6 +200,16 b' def create_server(ui, repo):'
200 200 self.reqmaker = wsgiapplication(self.make_handler)
201 201 self.daemon_threads = True
202 202
203 addr, port = self.socket.getsockname()
204 if addr == '0.0.0.0':
205 addr = socket.gethostname()
206 else:
207 try:
208 addr = socket.gethostbyaddr(addr)[0]
209 except socket.error:
210 pass
211 self.addr, self.port = addr, port
212
203 213 def make_handler(self):
204 214 if self.webdir_conf:
205 215 hgwebobj = self.webdirmaker(self.webdir_conf)
@@ -219,7 +229,10 b' def create_server(ui, repo):'
219 229 raise hg.RepoError(_('IPv6 not available on this system'))
220 230 super(IPv6HTTPServer, self).__init__(*args, **kwargs)
221 231
222 if use_ipv6:
223 return IPv6HTTPServer((address, port), _hgwebhandler)
224 else:
225 return MercurialHTTPServer((address, port), _hgwebhandler)
232 try:
233 if use_ipv6:
234 return IPv6HTTPServer((address, port), _hgwebhandler)
235 else:
236 return MercurialHTTPServer((address, port), _hgwebhandler)
237 except socket.error, inst:
238 raise util.Abort(_('cannot start server: %s') % inst.args[1])
General Comments 0
You need to be logged in to leave comments. Login now