-
Notifications
You must be signed in to change notification settings - Fork 4
/
subscriber.c
42 lines (34 loc) · 953 Bytes
/
subscriber.c
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
/*
* Example used in following article:
*
* Implementace front zpráv podle normy POSIX
* https://www.root.cz/clanky/implementace-front-zprav-podle-normy-posix/
*/
#include <stdio.h>
#include <string.h>
#include <mqueue.h>
#define QUEUE_NAME "/queue1"
int main(void)
{
mqd_t message_queue_id;
char message_text[10000];
unsigned int sender;
int status;
message_queue_id = mq_open(QUEUE_NAME, O_RDWR);
if (message_queue_id == -1) {
perror("Unable to open queue");
return 2;
}
status = mq_receive(message_queue_id, message_text, sizeof(message_text), &sender);
if (status == -1) {
perror("Unable to receive message");
return 2;
}
printf("Received message (%d bytes) from %d: %s\n", status, sender, message_text);
status = mq_close(message_queue_id);
if (status == -1) {
perror("Unable to close message queue");
return 2;
}
return 0;
}