async def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor._loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise pulsar.ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') address = parse_address(self.cfg.address) # First create the sockets transport, _ = await loop.create_datagram_endpoint( asyncio.DatagramProtocol, address) sock = transport.get_extra_info('socket') self.monitor_sockets(monitor, [sock]) # TODO: if we don't do this the socket get closed for some reason try: del transport._sock except AttributeError: pass
def monitor_start(self, monitor): """Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. """ cfg = self.cfg loop = monitor._loop if not pulsar.platform.has_multiProcessSocket or cfg.concurrency == "thread": cfg.set("workers", 0) if not cfg.address: raise pulsar.ImproperlyConfigured("Could not open a socket. " "No address to bind to") ssl = None if cfg.cert_file or cfg.key_file: if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ValueError('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ValueError('key_file "%s" does not exist' % cfg.key_file) ssl = SSLContext(keyfile=cfg.key_file, certfile=cfg.cert_file) address = parse_address(self.cfg.address) # First create the sockets server = yield loop.create_server(Protocol, *address) addresses = [] sockets = [] for sock in server.sockets: addresses.append(sock.getsockname()) sockets.append(WrapSocket(sock)) server.loop.remove_reader(sock.fileno()) monitor.sockets = sockets monitor.ssl = ssl cfg.addresses = addresses
def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor.event_loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise pulsar.ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') ssl = None if cfg.cert_file or cfg.key_file: if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ValueError('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ValueError('key_file "%s" does not exist' % cfg.key_file) ssl = SSLContext(keyfile=cfg.key_file, certfile=cfg.cert_file) address = parse_address(self.cfg.address) # First create the sockets sockets = yield loop.start_serving(lambda: None, *address) addresses = [] for sock in sockets: assert loop.remove_reader( sock.fileno()), ("Could not remove reader") addresses.append(sock.getsockname()) monitor.params.sockets = [WrapSocket(s) for s in sockets] monitor.params.ssl = ssl self.addresses = addresses self.address = addresses[0]
def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor.event_loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise pulsar.ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') ssl = None if cfg.cert_file or cfg.key_file: if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ValueError('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ValueError('key_file "%s" does not exist' % cfg.key_file) ssl = SSLContext(keyfile=cfg.key_file, certfile=cfg.cert_file) address = parse_address(self.cfg.address) # First create the sockets sockets = yield loop.start_serving(lambda: None, *address) addresses = [] for sock in sockets: assert loop.remove_reader(sock.fileno()), ( "Could not remove reader") addresses.append(sock.getsockname()) monitor.params.sockets = [WrapSocket(s) for s in sockets] monitor.params.ssl = ssl self.addresses = addresses self.address = addresses[0]
async def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') address = parse_address(self.cfg.address) if cfg.cert_file or cfg.key_file: if not ssl: raise RuntimeError('No support for ssl') if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ImproperlyConfigured('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ImproperlyConfigured('key_file "%s" does not exist' % cfg.key_file) # First create the sockets try: server = await self.create_server(monitor, address) except socket.error as e: raise ImproperlyConfigured(e) from None else: monitor.servers[self.name] = server self.cfg.addresses = server.addresses
async def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor._loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') address = parse_address(self.cfg.address) if cfg.cert_file or cfg.key_file: if not ssl: raise RuntimeError('No support for ssl') if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ImproperlyConfigured('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ImproperlyConfigured('key_file "%s" does not exist' % cfg.key_file) # First create the sockets try: server = await loop.create_server(asyncio.Protocol, *address) except socket.error as e: raise ImproperlyConfigured(e) else: self.monitor_sockets(monitor, server.sockets)
async def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise pulsar.ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') address = parse_address(self.cfg.address) server = await self.create_server(monitor, address) monitor.servers[self.name] = server self.cfg.addresses = server.addresses
def monitor_start(self, monitor): """Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. """ cfg = self.cfg loop = monitor._loop if not pulsar.platform.has_multiProcessSocket or cfg.concurrency == "thread": cfg.set("workers", 0) if not cfg.address: raise pulsar.ImproperlyConfigured("Could not open a socket. " "No address to bind to") address = parse_address(self.cfg.address) # First create the sockets t, _ = yield loop.create_datagram_endpoint(DatagramProtocol, address) sock = t.get_extra_info("socket") assert loop.remove_reader(sock.fileno()) monitor.sockets = [WrapTransport(t)] cfg.addresses = [sock.getsockname()]
def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor._loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise pulsar.ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') address = parse_address(self.cfg.address) # First create the sockets t, _ = yield from loop.create_datagram_endpoint( asyncio.DatagramProtocol, address) sock = t.get_extra_info('socket') assert loop.remove_reader(sock.fileno()) cfg.addresses = [sock.getsockname()] monitor.sockets = [WrapTransport(t)]
def monitor_start(self, monitor): '''Create the socket listening to the ``bind`` address. If the platform does not support multiprocessing sockets set the number of workers to 0. ''' cfg = self.cfg loop = monitor._loop if (not pulsar.platform.has_multiProcessSocket or cfg.concurrency == 'thread'): cfg.set('workers', 0) if not cfg.address: raise ImproperlyConfigured('Could not open a socket. ' 'No address to bind to') ssl = None if cfg.cert_file or cfg.key_file: if cfg.cert_file and not os.path.exists(cfg.cert_file): raise ImproperlyConfigured('cert_file "%s" does not exist' % cfg.cert_file) if cfg.key_file and not os.path.exists(cfg.key_file): raise ImproperlyConfigured('key_file "%s" does not exist' % cfg.key_file) ssl = SSLContext(keyfile=cfg.key_file, certfile=cfg.cert_file) address = parse_address(self.cfg.address) # First create the sockets try: server = yield from loop.create_server(asyncio.Protocol, *address) except socket.error as e: raise ImproperlyConfigured(e) else: addresses = [] sockets = [] for sock in server.sockets: addresses.append(sock.getsockname()) sockets.append(sock) loop.remove_reader(sock.fileno()) monitor.sockets = sockets monitor.ssl = ssl cfg.addresses = addresses
def test_parse_ipv6(self): address = parse_address('[::1]') self.assertEqual(address, ('::1', 8000)) address = parse_address('[::1]:8070') self.assertEqual(address, ('::1', 8070))
def test_parse_ipv4(self): address = parse_address('127.0.0.1') self.assertEqual(address, ('127.0.0.1', 8000)) address = parse_address('127.0.0.1', 8060) self.assertEqual(address, ('127.0.0.1', 8060))
def test_parse_ipv6(self): address = parse_address("[::1]") self.assertEqual(address, ("::1", 8000)) address = parse_address("[::1]:8070") self.assertEqual(address, ("::1", 8070))
def test_parse_ipv4(self): address = parse_address("127.0.0.1") self.assertEqual(address, ("127.0.0.1", 8000)) address = parse_address("127.0.0.1", 8060) self.assertEqual(address, ("127.0.0.1", 8060))