1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
#+build linux, darwin, netbsd, openbsd, freebsd, haiku
package posix
import "core:c"
when ODIN_OS == .Darwin {
foreign import lib "system:System"
} else {
foreign import lib "system:c"
}
// sys/msg.h = XSI message queue structures
foreign lib {
/*
Provides various operation as specified by the given cmd.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgctl.html ]]
*/
@(link_name=LMSGCTL)
msgctl :: proc(msqid: FD, cmd: IPC_Cmd, buf: ^msqid_ds) -> result ---
/*
Returns the message queue identifier associated with the argument key.
Returns: -1 (setting errno) on failure, the identifier otherwise
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgget.html ]]
*/
msgget :: proc(key: key_t, msgflg: IPC_Flags) -> FD ---
/*
Read a message from the queue.
Returns: -1 (setting errno) on failure, the bytes received otherwise
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgrcv.html ]]
*/
msgrcv :: proc(
msgid: FD,
msgp: rawptr,
msgsz: c.size_t,
msgtyp: c.long,
msgflg: IPC_Flags,
) -> c.ssize_t ---
/*
Send a message on the queue.
[[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/msgsnd.html ]]
*/
msgsnd :: proc(msgid: FD, msgp: rawptr, msgsz: c.size_t, msgflg: IPC_Flags) -> result ---
}
when ODIN_OS == .NetBSD {
@(private) LMSGCTL :: "__msgctl50"
} else {
@(private) LMSGCTL :: "msgctl"
}
when ODIN_OS == .Darwin {
msgqnum_t :: distinct c.ulong
msglen_t :: distinct c.ulong
MSG_NOERROR :: 0o10000
msqid_ds :: struct #max_field_align(4) {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
msg_first: c.int32_t,
msg_last: c.int32_t,
msg_cbytes: msglen_t,
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_pad1: c.int32_t,
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_pad2: c.int32_t,
msg_ctime: time_t, /* [PSX] time of last change */
msg_pad3: c.int32_t,
msg_pad4: [4]c.int32_t,
}
} else when ODIN_OS == .FreeBSD {
msgqnum_t :: distinct c.ulong
msglen_t :: distinct c.ulong
MSG_NOERROR :: 0o10000
msqid_ds :: struct {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
__msg_first: rawptr,
__msg_last: rawptr,
msg_cbytes: msglen_t,
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_ctime: time_t, /* [PSX] time of last change */
}
} else when ODIN_OS == .NetBSD {
msgqnum_t :: distinct c.ulong
msglen_t :: distinct c.size_t
MSG_NOERROR :: 0o10000
msqid_ds :: struct {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_ctime: time_t, /* [PSX] time of last change */
_msg_first: rawptr,
_msg_last: rawptr,
_msg_cbytes: msglen_t,
}
} else when ODIN_OS == .OpenBSD {
msgqnum_t :: distinct c.ulong
msglen_t :: distinct c.ulong
MSG_NOERROR :: 0o10000
msqid_ds :: struct {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
__msg_first: rawptr,
__msg_last: rawptr,
msg_cbytes: msglen_t,
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_pad1: c.long,
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_pad2: c.long,
msg_ctime: time_t, /* [PSX] time of last change */
msg_pad3: c.long,
msg_pad4: [4]c.long,
}
} else when ODIN_OS == .Linux {
msgqnum_t :: distinct c.ulong
msglen_t :: distinct c.ulong
MSG_NOERROR :: 0o10000
msqid_ds :: struct {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_ctime: time_t, /* [PSX] time of last change */
msg_cbytes: c.ulong,
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
__unused: [2]c.ulong,
}
} else when ODIN_OS == .Haiku {
msgqnum_t :: distinct c.uint32_t
msglen_t :: distinct c.uint32_t
MSG_NOERROR :: 0o10000
msqid_ds :: struct {
msg_perm: ipc_perm, /* [PSX] operation permission structure */
msg_qnum: msgqnum_t, /* [PSX] number of messages currently on queue */
msg_qbytes: msglen_t, /* [PSX] maximum number of bytes allowed on queue */
msg_lspid: pid_t, /* [PSX] process ID of last msgsnd() */
msg_lrpid: pid_t, /* [PSX] process ID of last msgrcv() */
msg_stime: time_t, /* [PSX] time of last msgsnd() */
msg_rtime: time_t, /* [PSX] time of last msgrcv() */
msg_ctime: time_t, /* [PSX] time of last change */
}
}
|