def _correctly_configured(self): """ :return: True if the plugin is correctly configured to run. """ listen_address = self._listen_address listen_port = self._listen_port if listen_address and listen_port: with self._plugin_lock: # If we have an active instance then we're OK! if webserver.is_running(listen_address, listen_port): return True, CONFIG_OK # Test if it's possible to bind the address s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) bind_args = (listen_address, listen_port) try: s.bind(bind_args) except socket.error, se: msg = 'Failed to bind to address %s:%s, error: %s' fmt_args = list(bind_args) fmt_args.append(se) return False, msg % tuple(fmt_args) finally: s.close()
def _correctly_configured(self): """ :return: True if the plugin is correctly configured to run. """ listen_address = self._listen_address listen_port = self._listen_port if listen_address and listen_port: with self._plugin_lock: # If we have an active instance then we're OK! if webserver.is_running(listen_address, listen_port): return True # Test if it's possible to bind the address s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) try: s.bind((listen_address, listen_port)) except socket.error: return False finally: s.close() del s return True