def __init__(self, app, hostname, io_loop=None, ssl_options=None, **kwargs): log.warn('Graphite listener is started -- if you do not need graphite, turn it off in datadog.conf.') log.warn('Graphite relay uses pickle to transport messages. Pickle is not secured against remote execution exploits.') log.warn('See http://blog.nelhage.com/2011/03/exploiting-pickle/ for more details') self.app = app self.hostname = hostname TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def initialize( self, request_callback, no_keep_alive=False, io_loop=None, xheaders=False, ssl_options=None, protocol=None, decompress_request=False, chunk_size=None, max_header_size=None, idle_connection_timeout=None, body_timeout=None, max_body_size=None, max_buffer_size=None, ): self.request_callback = request_callback self.no_keep_alive = no_keep_alive self.xheaders = xheaders self.protocol = protocol self.conn_params = HTTP1ConnectionParameters( decompress=decompress_request, chunk_size=chunk_size, max_header_size=max_header_size, header_timeout=idle_connection_timeout or 3600, max_body_size=max_body_size, body_timeout=body_timeout, ) TCPServer.__init__( self, io_loop=io_loop, ssl_options=ssl_options, max_buffer_size=max_buffer_size, read_chunk_size=chunk_size ) self._connections = set()
def __init__(self, connect_cb, disconnect_cb, data_cb, port=12345, host=''): TCPServer.__init__(self) self.connect_callback = connect_cb self.disconnect_callback = disconnect_cb self.data_callback = data_cb self.clients = [] self.listen(port, host) logging.info('Listening on port: %i', port)
def __init__(self, request_callback, io_loop=None, auth_password=None, **kwargs): self.request_callback = request_callback self.stats = Stats() self.auth_password = auth_password self.require_auth = False if self.auth_password: self.require_auth = True TCPServer.__init__(self, io_loop=io_loop, **kwargs)
def __init__(self, request_callback, no_keep_alive=False, io_loop=None, xheaders=False, ssl_options=None, protocol=None, **kwargs): self.request_callback = request_callback self.no_keep_alive = no_keep_alive self.xheaders = xheaders self.protocol = protocol TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, port, prt_types, prt_types_handlers): PNFPServer.__init__(self, port, prt_types, prt_types_handlers) TCPServer.__init__(self) self.connection = None self.listen(self.port)
def __init__(self, storage, sender, io_loop=None, **kwargs): TCPServer.__init__(self, io_loop=io_loop, **kwargs) self.storage = storage if not os.path.exists(self.storage): os.mkdir(self.storage) self.loop = io_loop or ioloop.IOLoop.current() self.send_mail = sender self.loop.call_later(10, self.send_mails)
def _handle_connection(self, connection, address): print( "TLS client connected." ) # fd = connection.fileno() # print(" fd = ", fd) # ---- save the connection ----- if not hasattr(self, 'client_connections'): self.client_connections = [] self.client_connections.append(connection) TCPServer._handle_connection(self, connection, address)
def __init__(self, io_loop=None, ssl_options=None, gp_module=False, **kwargs): self.logger = logging.getLogger(self.__class__.__name__) self.gp_module = gp_module try: TCPServer.__init__(self, ssl_options=ssl_options, **kwargs) except: etype, evalue, etb = sys.exc_info() self.logger.error("Could not create tcp server. Exception: %s, Error: %s." % (etype, evalue)) self.gp_module.shutDown()
def __init__(self, port, prt_types, prt_types_handlers): PNFPServer.__init__(self, prt_types, prt_types_handlers) TCPServer.__init__(self) self.port = int(port) self.connection = None self.listen(self.port)
def __init__(self, p_name, p_callback, p_max_buffer_size=None, p_read_chunk_size=None): TCPServer.__init__(self, max_buffer_size=p_max_buffer_size, read_chunk_size=p_read_chunk_size) self._callback = p_callback self._name = p_name
def __init__(self, io_loop=None, ssl_options=None, gp_module=False, **kwargs): self.gp_module = gp_module TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, status=None, hass=None, io_loop=None, ssl_options=None, **kwargs): # logger.debug('tcp server started') self.clients = {} self._status = status self._hass = hass TCPServer.__init__(self, ssl_options=ssl_options, **kwargs)
def __init__(self, port, prt_types, prt_types_handlers): PNFPServer.__init__(self, prt_types, prt_types_handlers) TCPServer.__init__(self) self.port = int(port) self.ues = {} self.connection = None # self.listen(self.port, "127.0.0.1") self.listen(self.port)
class OnlyOnce(object): def __init__(self): self.tcp_server = TCPServer() try: self.tcp_server.listen(44556) except socket.error: raise OnlyOnceException() def __del__(self): if self.tcp_server is not None: self.tcp_server.stop()
def __init__(self, io_loop=None, ssl_options=None, gp_module=False, **kwargs): TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs) self.gp_module = gp_module self.address = socket.gethostname()
def __init__ (self, db_conn, cursor, role): self.conn = db_conn self.cur = cursor self.role = role if self.role == 'ota': self.conn_pool = DeviceServer.accepted_ota_conns else: self.conn_pool = DeviceServer.accepted_xchange_conns TCPServer.__init__(self)
def __init__(self, io_loop=None, ssl_options=None, **kwargs): self.cache = LRUCache(options.capacity) self.dbw = ioloop.PeriodicCallback(self.dbw_callback, options.interval, io_loop=io_loop) self.dbw.start() self.connection_pool = ConnectionPool(lambda: Connection(), max_size=options.max_connection) TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, torrent, max_peers=50, download_path='downloads', peer_id=peer_id(), storage_class=DiskStorage): TCPServer.__init__(self) self.peer_id = peer_id self.torrent = torrent self.max_peers = max_peers self.connected_peers = set() self.connecting_peers = set() self.unconnected_peers = set() self.storage = storage_class.from_torrent(torrent, base_path=download_path)
def __init__(self, rpc_class=None, io_loop=None, ssl_options=None, **kwargs): logging.info('a echo tcp server is started') assert rpc_class self.rpc_class = rpc_class TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, port, pt_types, pt_types_handlers): PNFPServer.__init__(self, pt_types, pt_types_handlers) TCPServer.__init__(self) self.port = int(port) self.connection = None self.listen(self.port) self.lvaps = {} self.__assoc_id = 0
def __init__(self, device_type, connection_type, proto, **kwargs): super().__init__(**kwargs) self.device_type = device_type self.connection_type = connection_type self.proto = proto self.devices = {} self.tcp_server = TCPServer() self.tcp_server.handle_stream = self.handle_stream self.connections = {}
def __init__(self, serverPort, salt, rate, pushAhead, packLimit, listenIp, listenPort): TCPServer.__init__(self) ioloop = IOLoop.current() connBase.__init__(self, ioloop, False) self.stream = u = UStreamClient(self, serverPort, salt, rate, pushAhead, packLimit) self.t = t = threading.Thread(target=u.doWork) t.setDaemon(True) IOLoop.current().add_callback(t.start) self.listen(listenPort, listenIp) self.connId = 0 self.startTime = getRunningTime()
def __init__(self, context, service_id, device_type, connection_type, proto, port): super().__init__(context=context, service_id=service_id, port=port) self.device_type = device_type self.connection_type = connection_type self.proto = proto self.devices = {} self.tcp_server = TCPServer() self.tcp_server.handle_stream = self.handle_stream self.connections = {}
def __init__(self, data_queue: Queue, log_name: str, inputs: Dict[str, str], name: str) -> None: Process.__init__(self, name=name) TCPServer.__init__(self, max_buffer_size=10485760000, read_chunk_size=104857600) self.address: str = inputs["address"] self.port: int = inputs["port"] self.log: Logger = getLogger(log_name) self.log.info("Starting dial out client[%s]", self.name) self.url: str = f"http://{self.address}:{self.port}" self._header_size: int = 12 self._header_struct: Struct = Struct(">hhhhi") self.data_queue: Queue = data_queue
def __init__(self, config, agentType): self._config = config self._log = getLogger() self._client = AsyncHTTPClient() self._syncClient = HTTPClient() self._agentType = agentType self._parseConfig() self._tunnel = 0 self._hangUp = False self._stream = None TCPServer.__init__(self)
def __init__(self, env): self._env = env self._client = AsyncHTTPClient() self._syncClient = HTTPClient() config = env.config self._cid = config.channel self._url = '%s://%s' % (config.protocol, config.server) self._hangUp = False TCPServer.__init__(self)
def start(self): self.server = TCPServer() self.server.handle_stream = self.handle_stream self.server.listen(options.proxy_port) self.port = options.proxy_port self.need_to_process = [] #print("Redis proxy listening at {}:{}".format(self.redis_endpoint, self.port)) print("Redis proxy listening on port {}".format(self.port)) self.loop = IOLoop.current() # On the next iteration of the IOLoop, we will attempt to connect to the Redis servers. self.loop.add_callback(self.connect_to_redis_servers) # Start the IOLoop! self.loop.start()
def start(self): self.tcp_server = TCPServer(max_buffer_size=MAX_BUFFER_SIZE) self.tcp_server.handle_stream = self.handle_stream for i in range(5): try: self.tcp_server.listen(self.port, self.ip) except EnvironmentError as e: # EADDRINUSE can happen sporadically when trying to bind # to an ephemeral port if self.port != 0 or e.errno != errno.EADDRINUSE: raise exc = e else: break else: raise exc
def __init__(self): TCPServer.__init__(self) stream = TStreamClient('0.0.0.0', 11223) TOUManagerBase.__init__(stream) #super(TOUManagerClient,self).__init__() #self.ustream = UStreamClient() self.stream = TStreamClient('0.0.0.0', 11223) work1 = PeriodicCallback(self.stream_to_map, 10) work1.start() self.outputMap_byConn = {} self.outputMap_byId = {} self.maxCacheSize = 10 * 1024 * 1024 self.outputSize = 0 self.listen(9999, '0.0.0.0') self.connMap = {} self.eachConnWriteLimit = 1024 * 1024 self.streamReadLeft = ''
def initialize( self, request_callback: Union[ httputil.HTTPServerConnectionDelegate, Callable[[httputil.HTTPServerRequest], None], ], no_keep_alive: bool = False, xheaders: bool = False, ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None, protocol: str = None, decompress_request: bool = False, chunk_size: int = None, max_header_size: int = None, idle_connection_timeout: float = None, body_timeout: float = None, max_body_size: int = None, max_buffer_size: int = None, trusted_downstream: List[str] = None, ) -> None: # This method's signature is not extracted with autodoc # because we want its arguments to appear on the class # constructor. When changing this signature, also update the # copy in httpserver.rst. self.request_callback = request_callback self.xheaders = xheaders self.protocol = protocol self.conn_params = HTTP1ConnectionParameters( decompress=decompress_request, chunk_size=chunk_size, max_header_size=max_header_size, header_timeout=idle_connection_timeout or 3600, max_body_size=max_body_size, body_timeout=body_timeout, no_keep_alive=no_keep_alive, ) TCPServer.__init__( self, ssl_options=ssl_options, max_buffer_size=max_buffer_size, read_chunk_size=chunk_size, ) self._connections = set() # type: Set[HTTP1ServerConnection] self.trusted_downstream = trusted_downstream
def __init__(self,serverPort,salt,rate,pushAhead,packLimit,listenIp,listenPort,timeoutTime,serverIp,\ MPort,LPort,IDose,DDose,LGot,MRate,LRate,span,limit,speed,dose2,closeTime,ONum,commandId): TCPServer.__init__(self) ioloop = IOLoop.current() connBase.__init__(self, ioloop, False) self.stream = u = UStreamClient(self,serverPort,salt,rate,pushAhead,packLimit,timeoutTime,serverIp,\ MPort,LPort,IDose,DDose,LGot,MRate,LRate,span,limit,speed,dose2,closeTime,ONum) self.t = t = threading.Thread(target=u.doWork) t.setDaemon(True) IOLoop.current().add_callback(t.start) self.listen(listenPort, listenIp) self.connId = 0 self.startTime = getRunningTime() self.commandId = commandId PeriodicCallback(self.readCommand, 500).start() PeriodicCallback(self.writeCommand, 500).start() PeriodicCallback(self.flushLog, 1000).start() self.exit = False self.logCache = []
def __init__(self, request_callback, no_keep_alive=False, io_loop=None, xheaders=False, ssl_options=None, protocol=None, gzip=False, chunk_size=None, max_header_size=None, idle_connection_timeout=None, body_timeout=None, max_body_size=None, max_buffer_size=None): self.request_callback = request_callback self.no_keep_alive = no_keep_alive self.xheaders = xheaders self.protocol = protocol self.conn_params = HTTP1ConnectionParameters( use_gzip=gzip, chunk_size=chunk_size, max_header_size=max_header_size, header_timeout=idle_connection_timeout or 3600, max_body_size=max_body_size, body_timeout=body_timeout) TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, max_buffer_size=max_buffer_size, read_chunk_size=chunk_size) self._connections = set()
def start(self): self.server = TCPServer() self.server.handle_stream = self.handle_stream self.server.listen(options.proxy_port) self.port = options.proxy_port self.need_to_process = [] #print("Redis proxy listening at {}:{}".format(self.redis_endpoint, self.port)) print("Redis proxy listening on port {}".format(self.port)) self.loop = IOLoop.current() # On the next iteration of the IOLoop, we will attempt to connect to the Redis servers. self.loop.add_callback(self.connect_to_redis_servers) # Start the IOLoop! self.loop.start() # Begin asynchronously processing IO operations for Lambdas. self.process_IO = PeriodicCallback(self.process_IO_operation, callback_time=100) self.process_IO.start()
def start(self): """Starts the service on the configured port and host, or uses an OS-assigned port if not provided. """ sock, port, host = self.build_socket() self.port = port self.host = host self.server = TCPServer() self.server.handle_stream = self.handle_stream self.server.add_socket(sock) self.server.start(self.procs)
def __init__(self, host="127.0.0.1", port=8000, handler=None, ssl_options=None, max_buffer_size=None, read_chunk_size=None, family=socket.AF_UNSPEC, backlog=128, reuse_port=False): self.server_entity.host = host self.server_entity.port = port self.server_entity.handler = handler.initialize(self) self.server_entity.family = family self.server_entity.backlog = backlog self.server_entity.reuse_port = reuse_port TCPServer.__init__(self, ssl_options=ssl_options, max_buffer_size=max_buffer_size, read_chunk_size=read_chunk_size)
def __init__(self, app, hostname, io_loop=None, ssl_options=None, **kwargs): log.warn( 'Graphite listener is started -- if you do not need graphite, turn it off in datadog.conf.' ) log.warn( 'Graphite relay uses pickle to transport messages. Pickle is not secured against remote execution exploits.' ) log.warn( 'See http://blog.nelhage.com/2011/03/exploiting-pickle/ for more details' ) self.app = app self.hostname = hostname TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, request_callback, no_keep_alive=False, io_loop=None, xheaders=False, ssl_options=None, protocol=None, gzip=False, chunk_size=None, max_header_size=None, idle_connection_timeout=None, body_timeout=None, max_body_size=None, max_buffer_size=None): # 回调对象,一个application对象,具有handlers的list self.request_callback = request_callback self.no_keep_alive = no_keep_alive self.xheaders = xheaders self.protocol = protocol self.conn_params = HTTP1ConnectionParameters( # 基本的连接参数 use_gzip=gzip, chunk_size=chunk_size, max_header_size=max_header_size, header_timeout=idle_connection_timeout or 3600, max_body_size=max_body_size, body_timeout=body_timeout) TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, max_buffer_size=max_buffer_size, read_chunk_size=chunk_size) self._connections = set() # 保存全部的连接
def start(self): self.tcp_server = TCPServer(max_buffer_size=MAX_BUFFER_SIZE, **self.server_args) self.tcp_server.handle_stream = self._handle_stream backlog = int(dask.config.get('distributed.comm.socket-backlog')) for i in range(5): try: # When shuffling data between workers, there can # really be O(cluster size) connection requests # on a single worker socket, make sure the backlog # is large enough not to lose any. sockets = netutil.bind_sockets(self.port, address=self.ip, backlog=backlog) except EnvironmentError as e: # EADDRINUSE can happen sporadically when trying to bind # to an ephemeral port if self.port != 0 or e.errno != errno.EADDRINUSE: raise exc = e else: self.tcp_server.add_sockets(sockets) break else: raise exc
def __init__(self, io_loop=None, **kwargs): TCPServer.__init__(self, io_loop=io_loop, **kwargs) Log.debug('==========io_loop:{}.'.format(io_loop))
def __init__(self, io_loop=None, ssl_options=None, ank_accessor = None, **kwargs): logging.info('a echo tcp server is started') self.event_listeners = set([]) self.ank_accessor = ank_accessor TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, gpio, io_loop=None, ssl_options=None, **kwargs): self.myGPIO = gpio TCPServer.__init__(self, io_loop=io_loop, ssl_options=ssl_options, **kwargs)
def __init__(self, mongodb_config): TCPServer.__init__(self,) self.__mongodb_handler = pagedbLogic.pagedbLogic(mongodb_config)
def test_stop_twice(self): sock, port = bind_unused_port() server = TCPServer() server.add_socket(sock) server.stop() server.stop()
class BaseTCPListener(Listener, RequireEncryptionMixin): def __init__(self, address, comm_handler, deserialize=True, default_port=0, **connection_args): self._check_encryption(address, connection_args) self.ip, self.port = parse_host_port(address, default_port) self.comm_handler = comm_handler self.deserialize = deserialize self.server_args = self._get_server_args(**connection_args) self.tcp_server = None self.bound_address = None def start(self): self.tcp_server = TCPServer(max_buffer_size=MAX_BUFFER_SIZE, **self.server_args) self.tcp_server.handle_stream = self._handle_stream backlog = int(dask.config.get('distributed.comm.socket-backlog')) for i in range(5): try: # When shuffling data between workers, there can # really be O(cluster size) connection requests # on a single worker socket, make sure the backlog # is large enough not to lose any. sockets = netutil.bind_sockets(self.port, address=self.ip, backlog=backlog) except EnvironmentError as e: # EADDRINUSE can happen sporadically when trying to bind # to an ephemeral port if self.port != 0 or e.errno != errno.EADDRINUSE: raise exc = e else: self.tcp_server.add_sockets(sockets) break else: raise exc def stop(self): tcp_server, self.tcp_server = self.tcp_server, None if tcp_server is not None: tcp_server.stop() def _check_started(self): if self.tcp_server is None: raise ValueError("invalid operation on non-started TCPListener") @gen.coroutine def _handle_stream(self, stream, address): address = self.prefix + unparse_host_port(*address[:2]) stream = yield self._prepare_stream(stream, address) if stream is None: # Preparation failed return logger.debug("Incoming connection from %r to %r", address, self.contact_address) local_address = self.prefix + get_stream_address(stream) comm = self.comm_class(stream, local_address, address, self.deserialize) self.comm_handler(comm) def get_host_port(self): """ The listening address as a (host, port) tuple. """ self._check_started() if self.bound_address is None: self.bound_address = get_tcp_server_address(self.tcp_server) # IPv6 getsockname() can return more a 4-len tuple return self.bound_address[:2] @property def listen_address(self): """ The listening address as a string. """ return self.prefix + unparse_host_port(*self.get_host_port()) @property def contact_address(self): """ The contact address as a string. """ host, port = self.get_host_port() host = ensure_concrete_host(host) return self.prefix + unparse_host_port(host, port)
def __init__(self, mysql_config): TCPServer.__init__(self,) self.__linkdb_logic = linkdbLogic.linkdbLogic(mysql_config)
def __init__(self): TCPServer.__init__(self) self.client_list = []
def __init__ (self, db_conn, cursor): self.conn = db_conn self.cur = cursor TCPServer.__init__(self)
def __init__(self, no_keep_alive=False, protocol=None, **kwargs): self.no_keep_alive = no_keep_alive self.protocol = protocol TCPServer.__init__(self, **kwargs)
def __init__ (self, db_conn, cursor, role): self.conn = db_conn self.cur = cursor self.role = role TCPServer.__init__(self)
def __init__(self,requestFactory): TCPServer.__init__(self) # meh! self.requestFactory = requestFactory self.connections = set()
def __init__ (self): self.role = 'xchange' TCPServer.__init__(self)