Reputation: 11
I've been working through this guide which outlines how to deal with message queues in Linux, and so far I haven't had any trouble.
http://beej.us/guide/bgipc/output/html/multipage/mq.html
However, I was wondering what I would have to do to modify the sample programs so that the message is delivered to a different recipient, depending on the message that is sent. Eg: If message begins with the text 'URGENT', deliver to recipient A, else, deliver to recipient B.
I know I will need a second recipient class, but am not sure how to implement this feature.
Upvotes: 0
Views: 130
Reputation: 19375
I know I will need a second recipient class, but am not sure how to implement this feature.
By a second recipient class you have got to mean a second message queue. Since the message queue identifier key
in the sample programs is created by key = ftok("kirk.c", 'B')
, an obvious choice for the second key is keyurg = ftok("kirk.c", 'A')
, with which you msgget()
the second queue (say msqidurg
) in the sender as well as in the receiver. When it comes to sending a message:
if (msgsnd(strncmp(buf.mtext, "URGENT", 6) ? msqid : msqidurg, &buf, len+1, 0) < 0)
perror("msgsnd");
Upvotes: 0