poll.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-09-11 Meco Man First version
  9. * 2024-03-29 TroyMitchelle Add all macro comments and comments to structure members
  10. */
  11. #ifndef __POLL_H__
  12. #define __POLL_H__
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. #ifdef RT_USING_MUSLLIBC
  17. #if !defined(POLLIN) && !defined(POLLOUT)
  18. #define POLLIN 0x001 /**< There is data to read. */
  19. #define POLLPRI 0x002 /**< There is urgent data to read. */
  20. #define POLLOUT 0x004 /**< Writing is now possible. */
  21. #define POLLERR 0x008 /**< Error condition. */
  22. #define POLLHUP 0x010 /**< Hang up. */
  23. #define POLLNVAL 0x020 /**< Invalid polling request. */
  24. #define POLLRDNORM 0x040 /**< Normal data may be read. */
  25. #define POLLRDBAND 0x080 /**< Priority data may be read. */
  26. #define POLLWRNORM 0x100 /**< Writing normal data is possible. */
  27. #define POLLWRBAND 0x200 /**< Writing priority data is possible. */
  28. typedef unsigned int nfds_t;
  29. struct pollfd
  30. {
  31. int fd; /**< File descriptor. */
  32. short events; /**< Requested events. */
  33. short revents; /**< Returned events. */
  34. };
  35. #endif
  36. #else
  37. #if !defined(POLLIN) && !defined(POLLOUT)
  38. #define POLLIN 0x1 /**< There is data to read. */
  39. #define POLLOUT 0x2 /**< Writing is now possible. */
  40. #define POLLERR 0x4 /**< Error condition. */
  41. #define POLLNVAL 0x8 /**< Invalid polling request. */
  42. /* Below values are unimplemented */
  43. #define POLLRDNORM 0x10 /**< Normal data may be read. */
  44. #define POLLRDBAND 0x20 /**< Priority data may be read. */
  45. #define POLLPRI 0x40 /**< There is urgent data to read. */
  46. #define POLLWRNORM 0x80 /**< Writing normal data is possible. */
  47. #define POLLWRBAND 0x100 /**< Writing priority data is possible. */
  48. #define POLLHUP 0x200 /**< Hang up. */
  49. typedef unsigned int nfds_t;
  50. struct pollfd
  51. {
  52. int fd; /**< File descriptor. */
  53. short events; /**< Requested events. */
  54. short revents; /**< Returned events. */
  55. };
  56. #endif
  57. #endif /* !defined(POLLIN) && !defined(POLLOUT) */
  58. #define POLLMASK_DEFAULT (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)
  59. int poll(struct pollfd *fds, nfds_t nfds, int timeout);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* __POLL_H__ */