我们从Python开源项目中,提取了以下26个代码示例,用于说明如何使用asyncore.file_dispatcher()。
def __init__(self, options={}): self.secret = options.get('secret','') self.port = options.get('port',11111) self.buffer = [] self.loadbalancer_pool = [] _tap = options.get('tap', True) _name = options.get('name', '') self.dev = TapDevice(tap=_tap, name=_name) asyncore.file_dispatcher.__init__(self, self.dev.getFD()) self.dev.up() if options.get('tunnel_address', False): self.dev.ifconfig(address=options.get('tunnel_address')) logging.debug('Interface ready')
def __init__(self, callback, queue_number=0, debug=False): Thread.__init__(self) self.debug=debug self._stop = False self.nf_queue_started=False self.queue_number=queue_number self.q = nfqueue.queue() self.printDebug("Setting callback") self.q.set_callback(callback) self.printDebug("Open nfqueue number %s" % self.queue_number) try: self.q.fast_open(self.queue_number, AF_INET6) self.fd = self.q.get_fd() self.q.set_queue_maxlen(100000) asyncore.file_dispatcher.__init__(self, self.fd, None) self.q.set_mode(nfqueue.NFQNL_COPY_PACKET) except: self._stop = True print "Impossible to open NetFilter Queue {}".format(self.queue_number) return self.nf_queue_started=True self.printDebug("Queue is ready")
def __init__ (self, logger = None): r, w = os.pipe() self.trigger = w self.logger = logger asyncore.file_dispatcher.__init__ (self, r) self.lock = _thread.allocate_lock() self.thunks = []
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None, channel_map=None): """ Initializes the async notifier. The only additional parameter is 'channel_map' which is the optional asyncore private map. See Notifier class for the meaning of the others parameters. """ Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout) asyncore.file_dispatcher.__init__(self, self._fd, channel_map)
def __init__(self, f): asyncore.file_dispatcher.__init__(self,f) self.buffer=""
def test_dispatcher(self): fd = os.open(TESTFN, os.O_RDONLY) data = [] class FileDispatcher(asyncore.file_dispatcher): def handle_read(self): data.append(self.recv(29)) s = FileDispatcher(fd) os.close(fd) asyncore.loop(timeout=0.01, use_poll=True, count=2) self.assertEqual(b"".join(data), self.d)
def __init__(self, options={}): self.shutdown = False # Loadbalancers shouldn't reconnect self.buffer = [] self.loadbalancing_pool = [] self.rr = 0 # RoundRobin iterator counter self.weighted_rr_queue = [] # Weighted RoundRobin queue self.secret = options.get('secret','') self.port = options.get('port',11111) mode = options.get('mode','rr') if mode not in self.available_modes.keys(): logging.error('Unknown Mode "{}"!'.format(mode)) self.balancing_mode = self.available_modes.get(mode, 'rr') _tap = options.get('tap', True) _name = options.get('name', '') _mtu = 1496-28-200 self.dev = TapDevice(tap=_tap, name=_name) self.dev.ifconfig(mtu=_mtu) asyncore.file_dispatcher.__init__(self, self.dev.getFD()) self.dev.up() if options.get('tunnel_address', False): self.dev.ifconfig(address=options.get('tunnel_address')) logging.debug('Interface ready')
def test_dispatcher(self): fd = os.open(support.TESTFN, os.O_RDONLY) data = [] class FileDispatcher(asyncore.file_dispatcher): def handle_read(self): data.append(self.recv(29)) s = FileDispatcher(fd) os.close(fd) asyncore.loop(timeout=0.01, use_poll=True, count=2) self.assertEqual(b"".join(data), self.d)
def init_file_dispatcher(self, fd): """ Kludge to plug asyncore.file_dispatcher into asynchat. Call from subclass's __init__() method, after calling PDUChannel.__init__(), and don't read this on a full stomach. """ self.connected = True self._fileno = fd self.socket = asyncore.file_wrapper(fd) self.add_channel() flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) flags = flags | os.O_NONBLOCK fcntl.fcntl(fd, fcntl.F_SETFL, flags)
def __init__(self, channel, function, *args): self.parent = channel self.function = function self.args = args self.pipe = rfd, wfd = os.pipe() asyncore.file_dispatcher.__init__(self, rfd)
def __init__(self): r, w = os.pipe() self.trigger = w asyncore.file_dispatcher.__init__(self, r) self.lock = thread.allocate_lock() self.thunks = []
def handle_close(self): self.close() #end class PipeReader(asyncore.file_dispatcher).