poll.odin 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package posix
  2. import "base:intrinsics"
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // poll.h - definitions for the poll() function
  10. foreign lib {
  11. /*
  12. For each pointer in fds, poll() shall examine the given descriptor for the events.
  13. poll will identify on which descriptors writes or reads can be done.
  14. Returns: -1 (setting errno) on failure, 0 on timeout, the amount of fds that have been changed on success.
  15. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html ]]
  16. */
  17. poll :: proc(fds: [^]pollfd, nfds: nfds_t, timeout: c.int) -> c.int ---
  18. }
  19. nfds_t :: c.uint
  20. Poll_Event_Bits :: enum c.short {
  21. // Data other than high-priority data may be read without blocking.
  22. IN = log2(POLLIN),
  23. // Normal data may be read without blocking.
  24. RDNORM = log2(POLLRDNORM),
  25. // Priority data may be read without blocking.
  26. RDBAND = log2(POLLRDBAND),
  27. // High priority data may be read without blocking.
  28. PRI = log2(POLLPRI),
  29. // Normal data may be written without blocking.
  30. OUT = log2(POLLOUT),
  31. // Equivalent to POLLOUT.
  32. WRNORM = log2(POLLWRNORM),
  33. // Priority data may be written.
  34. WRBAND = log2(POLLWRBAND),
  35. // An error has occurred (revents only).
  36. ERR = log2(POLLERR),
  37. // Device hsa been disconnected (revents only).
  38. HUP = log2(POLLHUP),
  39. // Invalid fd member (revents only).
  40. NVAL = log2(POLLNVAL),
  41. }
  42. Poll_Event :: bit_set[Poll_Event_Bits; c.short]
  43. when ODIN_OS == .Darwin || ODIN_OS == .FreeBSD || ODIN_OS == .NetBSD || ODIN_OS == .OpenBSD {
  44. pollfd :: struct {
  45. fd: FD, /* [PSX] the following descriptor being polled */
  46. events: Poll_Event, /* [PSX] the input event flags */
  47. revents: Poll_Event, /* [PSX] the output event flags */
  48. }
  49. POLLIN :: 0x0001
  50. POLLRDNORM :: 0x0040
  51. POLLRDBAND :: 0x0080
  52. POLLPRI :: 0x0002
  53. POLLOUT :: 0x0004
  54. POLLWRNORM :: POLLOUT
  55. POLLWRBAND :: 0x0100
  56. POLLERR :: 0x0008
  57. POLLHUP :: 0x0010
  58. POLLNVAL :: 0x0020
  59. } else {
  60. #panic("posix is unimplemented for the current target")
  61. }