def pollEvents(self, wait): ret = [] epwrite = select.EPOLLOUT | select.EPOLLWRNORM | select.EPOLLWRBAND epread = select.EPOLLIN | select.EPOLLRDNORM | select.EPOLLRDBAND | select.EPOLLPRI eperr = select.EPOLLERR ephup = select.EPOLLHUP if self.socketCounter <= 0 and wait is None: return ([], True) generateFree = False if wait is None or (self.maxwait is not None and wait > self.maxwait): generateFree = True wait = self.maxwait events = [] try: interrupted = False self.shouldraise = True if wait is None: events = self.epoll.poll() else: events = self.epoll.poll(wait) self.shouldraise = False except InterruptedBySignalException: interrupted = True except IOError as exc: if exc.args[0] == errno.EINTR: interrupted = True else: raise finally: self.shouldraise = False for fd, e in events: if e & epwrite: ret.append( PollEvent(fd, PollEvent.WRITE_READY, e & epwrite)) if e & epread: ret.append(PollEvent(fd, PollEvent.READ_READY, e & epread)) if e & eperr: ret.append(PollEvent(fd, PollEvent.ERROR, e & eperr)) if e & ephup: ret.append(PollEvent(fd, PollEvent.HANGUP, e & ephup)) if not ret and generateFree and not interrupted: ret.append( SystemControlLowPriorityEvent( SystemControlLowPriorityEvent.FREE)) return (ret, False)
def pollEvents(self, wait): ret = [] if self.socketCounter <= 0 and wait is None: return ([], True) generateFree = False if wait is None or (self.maxwait is not None and wait > self.maxwait): generateFree = True wait = self.maxwait events = [[], [], []] try: interrupted = False self.shouldraise = True if wait is None: events = select.select(self.readfiles, self.writefiles, self.errorfiles) elif not self.readfiles and not self.writefiles and not self.errorfiles: time.sleep(wait) else: events = select.select(self.readfiles, self.writefiles, self.errorfiles, wait) self.shouldraise = False except InterruptedBySignalException: interrupted = True except IOError as exc: if exc.args[0] == errno.EINTR: interrupted = True else: raise IOError( 'Some of the fds are invalid, maybe some sockets are not unregistered', exc) finally: self.shouldraise = False for fd in events[0]: ret.append( PollEvent(fd, PollEvent.READ_READY, PollEvent.READ_READY)) for fd in events[1]: ret.append( PollEvent(fd, PollEvent.WRITE_READY, PollEvent.WRITE_READY)) for fd in events[2]: ret.append(PollEvent(fd, PollEvent.ERROR, PollEvent.ERROR)) if not ret and generateFree and not interrupted: ret.append( SystemControlLowPriorityEvent( SystemControlLowPriorityEvent.FREE)) return (ret, False)
def __init__(self): ''' Constructor ''' if hasattr(self, 'logging'): if isinstance(self.logging, dict): logging_config = dict(self.logging) else: logging_config = self.logging.todict() logging_config.setdefault('disable_existing_loggers', False) logging.config.dictConfig(logging_config) elif hasattr(self, 'loggingconfig'): logging.config.fileConfig(self.loggingconfig, disable_existing_loggers=False) self.scheduler = Scheduler(DefaultPolling(), getattr(self, 'processevents', None), getattr(self, 'queuedefaultsize', None), getattr(self, 'queuemaxsize', None), defaultQueueClass=CBQueue.AutoClassQueue.initHelper('_classname0'), defaultQueuePriority = 400) if self.debugging: self.scheduler.debugging = True self.scheduler.logger.setLevel(logging.DEBUG) self.scheduler.queue.addSubQueue(self.pollwritepriority, PollEvent.createMatcher(category=PollEvent.WRITE_READY), 'write', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(self.pollreadpriority, PollEvent.createMatcher(category=PollEvent.READ_READY), 'read', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(self.pollerrorpriority, PollEvent.createMatcher(category=PollEvent.ERROR), 'error') self.scheduler.queue.addSubQueue(self.connectioncontrolpriority, ConnectionControlEvent.createMatcher(), 'control') self.scheduler.queue.addSubQueue(self.connectionwritepriority, ConnectionWriteEvent.createMatcher(), 'connectionwrite', self.totalwritelimit, self.totalwritelimit, CBQueue.AutoClassQueue.initHelper('connection', self.preservefornew, subqueuelimit = self.writelimitperconnection)) self.scheduler.queue.addSubQueue(self.streamdatapriority, StreamDataEvent.createMatcher(), 'streamdata', self.streamdatalimit, self.streamdatalimit, CBQueue.AutoClassQueue.initHelper('stream', self.preservefornew, subqueuelimit = self.datalimitperstream)) self.scheduler.queue.addSubQueue(self.routinecontrolpriority, RoutineControlEvent.createMatcher(), 'routine') self.scheduler.queue.addSubQueue(self.timerpriority, TimerEvent.createMatcher(), 'timer') self.scheduler.queue.addSubQueue(self.resolverresppriority, ResolveResponseEvent.createMatcher(), 'resolve') self.scheduler.queue.addSubQueue(self.resolverreqpriority, ResolveRequestEvent.createMatcher(), 'resolvereq', 16) self.scheduler.queue.addSubQueue(self.sysctlpriority, SystemControlEvent.createMatcher(), 'sysctl') self.scheduler.queue.addSubQueue(self.sysctllowpriority, SystemControlLowPriorityEvent.createMatcher(), 'sysctllow') self.scheduler.queue.addSubQueue(self.moduleapicallpriority, ModuleAPICall.createMatcher(), 'moduleapi', None, None, CBQueue.AutoClassQueue.initHelper('target', 2, subqueuelimit = 5)) self.scheduler.queue.addSubQueue(self.moduleapireplypriority, ModuleAPIReply.createMatcher(), 'moduleapireply') self.scheduler.queue.addSubQueue(self.modulenotifypriority, ModuleNotification.createMatcher(), 'modulenotify', None, None, CBQueue.AutoClassQueue.initHelper('target', subqueuelimit=5)) self.scheduler.queue.addSubQueue(self.moduleloadeventpriority, ModuleLoadStateChanged.createMatcher(), 'moduleload') self.scheduler.queue.addSubQueue(self.lockpriority, LockEvent.createMatcher(), 'lock', None, None, CBQueue.AutoClassQueue.initHelper('key', subqueuelimit=1)) self.scheduler.queue.addSubQueue(self.futurepriority, FutureEvent.createMatcher(), 'future') self.resolver = Resolver(self.scheduler, self.resolverpoolsize) self.moduleloader = ModuleLoader(self)
def __init__(self): ''' Constructor ''' if hasattr(self, 'logging'): if isinstance(self.logging, dict): logging_config = dict(self.logging) else: logging_config = self.logging.todict() logging_config.setdefault('disable_existing_loggers', False) logging.config.dictConfig(logging_config) elif hasattr(self, 'loggingconfig'): logging.config.fileConfig(self.loggingconfig, disable_existing_loggers=False) self.scheduler = Scheduler(DefaultPolling(), getattr(self, 'processevents', None), getattr(self, 'queuedefaultsize', None), getattr(self, 'queuemaxsize', None), defaultQueueClass=CBQueue.AutoClassQueue.initHelper('_classname0'), defaultQueuePriority = 400) if self.debugging: self.scheduler.debugging = True self.scheduler.logger.setLevel(logging.DEBUG) self.scheduler.queue.addSubQueue(self.pollwritepriority, PollEvent.createMatcher(category=PollEvent.WRITE_READY), 'write', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(self.pollreadpriority, PollEvent.createMatcher(category=PollEvent.READ_READY), 'read', None, None, CBQueue.AutoClassQueue.initHelper('fileno')) self.scheduler.queue.addSubQueue(self.pollerrorpriority, PollEvent.createMatcher(category=PollEvent.ERROR), 'error') self.scheduler.queue.addSubQueue(self.connectioncontrolpriority, ConnectionControlEvent.createMatcher(), 'control') self.scheduler.queue.addSubQueue(self.connectionwritepriority, ConnectionWriteEvent.createMatcher(), 'connectionwrite', self.totalwritelimit, self.totalwritelimit, CBQueue.AutoClassQueue.initHelper('connection', self.preservefornew, subqueuelimit = self.writelimitperconnection)) self.scheduler.queue.addSubQueue(self.streamdatapriority, StreamDataEvent.createMatcher(), 'streamdata', self.streamdatalimit, self.streamdatalimit, CBQueue.AutoClassQueue.initHelper('stream', self.preservefornew, subqueuelimit = self.datalimitperstream)) self.scheduler.queue.addSubQueue(self.routinecontrolpriority, RoutineControlEvent.createMatcher(), 'routine') self.scheduler.queue.addSubQueue(self.timerpriority, TimerEvent.createMatcher(), 'timer') self.scheduler.queue.addSubQueue(self.resolverresppriority, ResolveResponseEvent.createMatcher(), 'resolve') self.scheduler.queue.addSubQueue(self.resolverreqpriority, ResolveRequestEvent.createMatcher(), 'resolvereq', 16) self.scheduler.queue.addSubQueue(self.sysctlpriority, SystemControlEvent.createMatcher(), 'sysctl') self.scheduler.queue.addSubQueue(self.sysctllowpriority, SystemControlLowPriorityEvent.createMatcher(), 'sysctllow') self.scheduler.queue.addSubQueue(self.moduleapicallpriority, ModuleAPICall.createMatcher(), 'moduleapi', None, None, CBQueue.AutoClassQueue.initHelper('target', 2, subqueuelimit = 5)) self.scheduler.queue.addSubQueue(self.moduleapireplypriority, ModuleAPIReply.createMatcher(), 'moduleapireply') self.scheduler.queue.addSubQueue(self.modulenotifypriority, ModuleNotification.createMatcher(), 'modulenotify', None, None, CBQueue.AutoClassQueue.initHelper('target', subqueuelimit=5)) self.scheduler.queue.addSubQueue(self.moduleloadeventpriority, ModuleLoadStateChanged.createMatcher(), 'moduleload') self.scheduler.queue.addSubQueue(self.lockpriority, LockEvent.createMatcher(), 'lock', None, None, CBQueue.AutoClassQueue.initHelper('key', subqueuelimit=1)) self.resolver = Resolver(self.scheduler, self.resolverpoolsize) self.moduleloader = ModuleLoader(self)