diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-03-12 13:47:37 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-03-12 13:47:37 +1300 |
commit | 40e9067b831641820019ea808d6c0099a668a03c (patch) | |
tree | f63278cdfbc4a1b3228f0b574f51952298c2985a /libmproxy/proxy.py | |
parent | 9f16a84a9e771dbbc3314daafaf63449de73d3eb (diff) | |
download | mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.tar.gz mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.tar.bz2 mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.zip |
Handle invalid bind address specifications gracefully.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r-- | libmproxy/proxy.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index bff67000..8c9302fe 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -726,14 +726,22 @@ class ProxyHandler(SocketServer.StreamRequestHandler): pass +class ProxyServerError(Exception): pass + ServerBase = SocketServer.ThreadingTCPServer ServerBase.daemon_threads = True # Terminate workers when main thread terminates class ProxyServer(ServerBase): request_queue_size = 20 allow_reuse_address = True def __init__(self, config, port, address=''): + """ + Raises ProxyServerError if there's a startup problem. + """ self.config, self.port, self.address = config, port, address - ServerBase.__init__(self, (address, port), ProxyHandler) + try: + ServerBase.__init__(self, (address, port), ProxyHandler) + except socket.error, v: + raise ProxyServerError('Error starting proxy server: ' + v.strerror) self.masterq = None self.certdir = tempfile.mkdtemp(prefix="mitmproxy") config.certdir = self.certdir |