sys_msg.odin 5.3 KB

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