array.h 812 B

1234567891011121314151617181920212223242526272829303132
  1. #ifndef __API_FD_ARRAY__
  2. #define __API_FD_ARRAY__
  3. #include <stdio.h>
  4. struct pollfd;
  5. struct fdarray {
  6. int nr;
  7. int nr_alloc;
  8. int nr_autogrow;
  9. struct pollfd *entries;
  10. };
  11. void fdarray__init(struct fdarray *fda, int nr_autogrow);
  12. void fdarray__exit(struct fdarray *fda);
  13. struct fdarray *fdarray__new(int nr_alloc, int nr_autogrow);
  14. void fdarray__delete(struct fdarray *fda);
  15. int fdarray__add(struct fdarray *fda, int fd, short revents);
  16. int fdarray__poll(struct fdarray *fda, int timeout);
  17. int fdarray__filter(struct fdarray *fda, short revents);
  18. int fdarray__grow(struct fdarray *fda, int extra);
  19. int fdarray__fprintf(struct fdarray *fda, FILE *fp);
  20. static inline int fdarray__available_entries(struct fdarray *fda)
  21. {
  22. return fda->nr_alloc - fda->nr;
  23. }
  24. #endif /* __API_FD_ARRAY__ */