sys_msg.odin 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. // NOTE: this is #pragma pack(4)
  50. msqid_ds :: struct #align(4) {
  51. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  52. msg_first: c.int32_t,
  53. msg_last: c.int32_t,
  54. msg_cbytes: msglen_t,
  55. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  56. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  57. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  58. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  59. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  60. msg_pad1: c.int32_t,
  61. using _: struct #align(4) {
  62. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  63. msg_pad2: c.int32_t,
  64. using _: struct #align(4) {
  65. msg_ctime: time_t, /* [PSX] time of last change */
  66. msg_pad3: c.int32_t,
  67. msg_pad4: [4]c.int32_t,
  68. },
  69. },
  70. }
  71. } else when ODIN_OS == .FreeBSD {
  72. msgqnum_t :: distinct c.ulong
  73. msglen_t :: distinct c.ulong
  74. MSG_NOERROR :: 0o10000
  75. msqid_ds :: struct {
  76. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  77. __msg_first: rawptr,
  78. __msg_last: rawptr,
  79. msg_cbytes: msglen_t,
  80. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  81. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  82. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  83. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  84. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  85. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  86. msg_ctime: time_t, /* [PSX] time of last change */
  87. }
  88. } else when ODIN_OS == .NetBSD {
  89. msgqnum_t :: distinct c.ulong
  90. msglen_t :: distinct c.size_t
  91. MSG_NOERROR :: 0o10000
  92. msqid_ds :: struct {
  93. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  94. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  95. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  96. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  97. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  98. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  99. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  100. msg_ctime: time_t, /* [PSX] time of last change */
  101. _msg_first: rawptr,
  102. _msg_last: rawptr,
  103. _msg_cbytes: msglen_t,
  104. }
  105. } else when ODIN_OS == .OpenBSD {
  106. msgqnum_t :: distinct c.ulong
  107. msglen_t :: distinct c.ulong
  108. MSG_NOERROR :: 0o10000
  109. msqid_ds :: struct {
  110. msg_perm: ipc_perm, /* [PSX] operation permission structure */
  111. __msg_first: rawptr,
  112. __msg_last: rawptr,
  113. msg_cbytes: msglen_t,
  114. msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
  115. msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
  116. msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
  117. msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
  118. msg_stime: time_t, /* [PSX] time of last msgsnd() */
  119. msg_pad1: c.long,
  120. msg_rtime: time_t, /* [PSX] time of last msgrcv() */
  121. msg_pad2: c.long,
  122. msg_ctime: time_t, /* [PSX] time of last change */
  123. msg_pad3: c.long,
  124. msg_pad4: [4]c.long,
  125. }
  126. } else {
  127. #panic("posix is unimplemented for the current target")
  128. }