def listenSSL(self, port, factory, contextFactory, backlog=50, interface=''): raise CannotListenError("Cannot BIND via HTTP proxies")
def startListening(self): self.logger.debug('startingListening') if not self.listening: self.listening = True if self.port: self.logger.debug('creating new site and resource') self.wrapped_factory = setup_site(self) self.wrapped_port = reactor.listenTCP(self.port, self.wrapped_factory, self.backlog, self.interface) elif self.resource and self.childName: self.logger.debug('adding into existing resource as %s' % self.childName) self.resource.putChild(self.childName, TCPResource(self)) else: raise CannotListenError("Already listening...")
def startListening(self): """Create and bind my socket, and begin listening on it. This is called on unserialization, and must be called after creating a server to begin listening on the specified port. """ if self._preexistingSocket is None: # Create a new socket and make it listen try: skt = self.createInternetSocket() if self.addressFamily == socket.AF_INET6: addr = _resolveIPv6(self.interface, self.port) else: addr = (self.interface, self.port) skt.bind(addr) except socket.error as le: raise CannotListenError(self.interface, self.port, le) skt.listen(self.backlog) else: # Re-use the externally specified socket skt = self._preexistingSocket self._preexistingSocket = None # Avoid shutting it down at the end. self._shouldShutdown = False # Make sure that if we listened on port 0, we update that to # reflect what the OS actually assigned us. self._realPortNumber = skt.getsockname()[1] log.msg("%s starting on %s" % ( self._getLogPrefix(self.factory), self._realPortNumber)) # The order of the next 5 lines is kind of bizarre. If no one # can explain it, perhaps we should re-arrange them. self.factory.doStart() self.connected = True self.socket = skt self.fileno = self.socket.fileno self.numberAccepts = 100 self.startReading()
def listenUDP(self, port, *args, **kwargs): ports.append(port) err = OSError(errno.EMFILE, "Out of files :(") raise CannotListenError(None, port, err)
def listenUDP(self, port, *args, **kwargs): ports.append(port) raise CannotListenError(None, port, None)
def start_core( listen_port=58846, logfile=None, timeout=10, timeout_msg=None, custom_script='', print_stdout=True, print_stderr=True, extra_callbacks=None, ): """Start the deluge core as a daemon. Args: listen_port (int, optional): The port the daemon listens for client connections. logfile (str, optional): Logfile name to write the output from the process. timeout (int): If none of the callbacks have been triggered before the imeout, the process is killed. timeout_msg (str): The message to print when the timeout expires. custom_script (str): Extra python code to insert into the daemon process script. print_stderr (bool): If the output from the process' stderr should be printed to stdout. print_stdout (bool): If the output from the process' stdout should be printed to stdout. extra_callbacks (list): A list of dictionaries specifying extra callbacks. Returns: tuple(Deferred, ProcessOutputHandler): The Deferred is fired when the core callback is triggered either after the default output triggers are matched (daemon successfully started, or failed to start), or upon timeout expiry. The ProcessOutputHandler is the handler for the deluged process. """ config_directory = set_tmp_config_dir() daemon_script = """ import sys import deluge.core.daemon_entry from deluge.common import windows_check if windows_check(): sys.argv.extend(['-c', '%(dir)s', '-L', 'info', '-p', '%(port)d']) else: sys.argv.extend(['-d', '-c', '%(dir)s', '-L', 'info', '-p', '%(port)d']) try: daemon = deluge.core.daemon_entry.start_daemon(skip_start=True) %(script)s daemon.start() except Exception: import traceback sys.stderr.write('Exception raised:\\n %%s' %% traceback.format_exc()) """ % { 'dir': config_directory, 'port': listen_port, 'script': custom_script, } callbacks = [] default_core_cb = {'deferred': Deferred(), 'types': 'stdout'} if timeout: default_core_cb['timeout'] = timeout # Specify the triggers for daemon log output default_core_cb['triggers'] = [ { 'expr': 'Finished loading ', 'value': lambda reader, data, data_all: reader }, { 'expr': 'Could not listen on localhost:%d' % (listen_port), 'type': 'errback', # Error from libtorrent 'value': lambda reader, data, data_all: CannotListenError( 'localhost', listen_port, 'Could not start deluge test client!\n%s' % data, ), }, { 'expr': 'Traceback', 'type': 'errback', 'value': lambda reader, data, data_all: DelugeError( 'Traceback found when starting daemon:\n%s' % data), }, ] callbacks.append(default_core_cb) if extra_callbacks: callbacks.extend(extra_callbacks) process_protocol = start_process(daemon_script, callbacks, logfile, print_stdout, print_stderr) return default_core_cb['deferred'], process_protocol
def listenUDP(self, port, *args): ports.append(port) if len(ports) == 1: raise CannotListenError(None, port, None)
def listenTCP(port, factory, backlog=50, interface=''): raise CannotListenError("Cannot BIND via HTTP proxies")
def testSetupCannotListen(self, mock_peering, mock_listenTCP): mock_listenTCP.side_effect = CannotListenError(None, None, "Mocked") self.assertRaises(CannotListenError, self.bgpfailover.setup) mock_peering.assert_called()
def startListeningError(): raise CannotListenError(None, None, None)