diff options
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 |