本文整理汇总了Python中termios.FIONREAD属性的典型用法代码示例。如果您正苦于以下问题:Python termios.FIONREAD属性的具体用法?Python termios.FIONREAD怎么用?Python termios.FIONREAD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类termios
的用法示例。
在下文中一共展示了termios.FIONREAD属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_events
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def read_events(self):
"""
Read events from device, build _RawEvents, and enqueue them.
"""
buf_ = array.array('i', [0])
# get event queue size
if fcntl.ioctl(self._fd, termios.FIONREAD, buf_, 1) == -1:
return
queue_size = buf_[0]
if queue_size < self._threshold:
log.debug('(fd: %d) %d bytes available to read but threshold is '
'fixed to %d bytes', self._fd, queue_size,
self._threshold)
return
try:
# Read content from file
r = os.read(self._fd, queue_size)
except Exception, msg:
raise NotifierError(msg)
示例2: _is_closed_select
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def _is_closed_select(f):
rlist, wlist, _ = select.select([f], [f], [], 0.0)
if not rlist and not wlist:
return False
buf = array.array('i', [0])
fcntl.ioctl(f.fileno(), termios.FIONREAD, buf)
return buf[0] == 0
示例3: in_waiting
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def in_waiting(self):
"""Return the number of bytes currently in the input buffer."""
#~ s = fcntl.ioctl(self.fd, termios.FIONREAD, TIOCM_zero_str)
s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str)
return struct.unpack('I', s)[0]
# select based implementation, proved to work on many systems
示例4: out_waiting
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def out_waiting(self):
"""Return the number of bytes currently in the output buffer."""
#~ s = fcntl.ioctl(self.fd, termios.FIONREAD, TIOCM_zero_str)
s = fcntl.ioctl(self.fd, TIOCOUTQ, TIOCM_zero_str)
return struct.unpack('I', s)[0]
示例5: _running_jobs
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def _running_jobs(cls):
try:
buf = array.array('i', [0])
if fcntl.ioctl(cls._job_pipe[0], FIONREAD, buf) == 0:
return cls._max_jobs - buf[0]
except (NotImplementedError, OSError):
pass
return cls._max_jobs
示例6: read_events
# 需要导入模块: import termios [as 别名]
# 或者: from termios import FIONREAD [as 别名]
def read_events(self):
"""
Read events from device, build _RawEvents, and enqueue them.
"""
buf_ = array.array('i', [0])
# get event queue size
if fcntl.ioctl(self._fd, termios.FIONREAD, buf_, 1) == -1:
return
queue_size = buf_[0]
if queue_size < self._threshold:
log.debug('(fd: %d) %d bytes available to read but threshold is '
'fixed to %d bytes', self._fd, queue_size,
self._threshold)
return
try:
# Read content from file
r = os.read(self._fd, queue_size)
except Exception as msg:
raise NotifierError(msg)
log.debug('Event queue size: %d', queue_size)
rsum = 0 # counter
while rsum < queue_size:
s_size = 16
# Retrieve wd, mask, cookie and fname_len
wd, mask, cookie, fname_len = struct.unpack('iIII',
r[rsum:rsum+s_size])
# Retrieve name
bname, = struct.unpack('%ds' % fname_len,
r[rsum + s_size:rsum + s_size + fname_len])
# FIXME: should we explictly call sys.getdefaultencoding() here ??
uname = bname.decode()
rawevent = _RawEvent(wd, mask, cookie, uname)
if self._coalesce:
# Only enqueue new (unique) events.
raweventstr = str(rawevent)
if raweventstr not in self._eventset:
self._eventset.add(raweventstr)
self._eventq.append(rawevent)
else:
self._eventq.append(rawevent)
rsum += s_size + fname_len