sys_msg.odin 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package posix
  2. import "core:c"
  3. when ODIN_OS == .Darwin {
  4. foreign import lib "system:System.framework"
  5. } else {
  6. foreign import lib "system:c"
  7. }
  8. // sys/msg.h = XSI message queue structures
  9. foreign lib {
  10. /*
  11. Provides various operation as specified by the given cmd.
  12. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgctl.html ]]
  13. */
  14. @(link_name=LMSGCTL)
  15. msgctl :: proc(msqid: FD, cmd: IPC_Cmd, buf: ^msqid_ds) -> result ---
  16. /*
  17. Returns the message queue identifier associated with the argument key.
  18. Returns: -1 (setting errno) on failure, the identifier otherwise
  19. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgget.html ]]
  20. */
  21. msgget :: proc(key: key_t, msgflg: IPC_Flags) -> FD ---
  22. /*
  23. Read a message from the queue.
  24. Returns: -1 (setting errno) on failure, the bytes received otherwise
  25. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgrcv.html ]]
  26. */
  27. msgrcv :: proc(
  28. msgid: FD,
  29. msgp: rawptr,
  30. msgsz: c.size_t,
  31. msgtyp: c.long,
  32. msgflg: IPC_Flags,
  33. ) -> c.ssize_t ---
  34. /*
  35. Send a message on the queue.
  36. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgsnd.html ]]
  37. */
  38. msgsnd :: proc(msgid: FD, msgp: rawptr, msgsz: c.size_t, msgflg: IPC_Flags) -> result ---
  39. }
  40. when ODIN_OS == .NetBSD {
  41. @(private) LMSGCTL :: "__msgctl50"
  42. } else {
  43. @(private) LMSGCTL :: "msgctl"
  44. }
  45. when ODIN_OS == .Darwin {
  46. msgqnum_t :: distinct c.ulong
  47. msglen_t :: distinct c.ulong
  48. MSG_NOERROR :: 0o10000
  49. msqid_ds :: struct #max_field_align(4) {
  50. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  51. msg_first: c.int32_t,
  52. msg_last: c.int32_t,
  53. msg_cbytes: msglen_t,
  54. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  55. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  56. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  57. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  58. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  59. msg_pad1: c.int32_t,
  60. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  61. msg_pad2: c.int32_t,
  62. msg_ctime: time_t, /* [PSX] time of last change */
  63. msg_pad3: c.int32_t,
  64. msg_pad4: [4]c.int32_t,
  65. }
  66. } else when ODIN_OS == .FreeBSD {
  67. msgqnum_t :: distinct c.ulong
  68. msglen_t :: distinct c.ulong
  69. MSG_NOERROR :: 0o10000
  70. msqid_ds :: struct {
  71. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  72. __msg_first: rawptr,
  73. __msg_last: rawptr,
  74. msg_cbytes: msglen_t,
  75. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  76. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  77. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  78. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  79. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  80. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  81. msg_ctime: time_t, /* [PSX] time of last change */
  82. }
  83. } else when ODIN_OS == .NetBSD {
  84. msgqnum_t :: distinct c.ulong
  85. msglen_t :: distinct c.size_t
  86. MSG_NOERROR :: 0o10000
  87. msqid_ds :: struct {
  88. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  89. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  90. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  91. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  92. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  93. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  94. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  95. msg_ctime: time_t, /* [PSX] time of last change */
  96. _msg_first: rawptr,
  97. _msg_last: rawptr,
  98. _msg_cbytes: msglen_t,
  99. }
  100. } else when ODIN_OS == .OpenBSD {
  101. msgqnum_t :: distinct c.ulong
  102. msglen_t :: distinct c.ulong
  103. MSG_NOERROR :: 0o10000
  104. msqid_ds :: struct {
  105. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  106. __msg_first: rawptr,
  107. __msg_last: rawptr,
  108. msg_cbytes: msglen_t,
  109. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  110. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  111. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  112. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  113. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  114. msg_pad1: c.long,
  115. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  116. msg_pad2: c.long,
  117. msg_ctime: time_t, /* [PSX] time of last change */
  118. msg_pad3: c.long,
  119. msg_pad4: [4]c.long,
  120. }
  121. } else {
  122. #panic("posix is unimplemented for the current target")
  123. }