fswait.py 624 B

1234567891011121314151617181920
  1. import ctypes
  2. _lib = None
  3. if not _lib:
  4. _lib = ctypes.CDLL('libc.so')
  5. _lib.syscall_fswait.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_int)]
  6. _lib.syscall_fswait.restype = ctypes.c_int
  7. _lib.syscall_fswait2.argtypes = [ctypes.c_int,ctypes.POINTER(ctypes.c_int),ctypes.c_int]
  8. _lib.syscall_fswait2.restype = ctypes.c_int
  9. def fswait(files,timeout=None):
  10. fds = (ctypes.c_int * len(files))()
  11. for i in range(len(files)):
  12. fds[i] = files[i].fileno()
  13. if timeout is None:
  14. return _lib.syscall_fswait(len(fds),fds)
  15. else:
  16. return _lib.syscall_fswait2(len(fds),fds,timeout)