Operating System - HP-UX
1833874 Members
2253 Online
110063 Solutions
New Discussion

Cloning Messages on System V Message Queue

 
SOLVED
Go to solution
Srikanth_14
Occasional Advisor

Cloning Messages on System V Message Queue

We have an application which is based on System V Message Queue running on HPUX. Data is sent/received on both ends of queue. Is there a way to clone the packets flowing through the queue. Suppose if there is another application attached to the same queue, is there any way to make copies of the packets and route the packets to all the applications attached to the end of the source queue. Any help on this regard would be highly appreciated.
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor

Re: Cloning Messages on System V Message Queue

There is no straighforward way to do this because msgrcv() remove the data from the message queue. You could, of course, then use msgsnd() to make multiple copies but you would typically have to redesign your entire protocol. Typically when I use message queues I let the clients send a request to the server with a low valued (e.g.) message type. The server then does a msgsnd and sets the msgtyp equal to the client's PID so that it alone gets the message meant for it because the client's msgrcv is looking only for msgtyp's set to its own PID.

If it ain't broke, I can fix that.
Srikanth_14
Occasional Advisor

Re: Cloning Messages on System V Message Queue

The application system which is Message Driven is a third party software and hence we are not in a position to modify the source. We are trying to analyze the message packets flowing through the Queues and hence require the messages to be cloned. Are there any workarounds to make multiple copies of the messages flowing through Messages Queues ?
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Cloning Messages on System V Message Queue

In that case, you are very limited. What you might be able to do is have a process doing a msgrcv() with msgtyp = 0 so that the first available message is read. As soon as it is read, you copy the data to buffers, do a msgsnd() to put the message back on the queue and then nanosleep a bit so that you don't read your own message in the next cycle. How well this would work depends upon the application's msg protocol works AND it assumes that the message queue was not setup as IPC_PRIVATE.
If it ain't broke, I can fix that.
Emil Velez
Honored Contributor

Re: Cloning Messages on System V Message Queue


You may want to make up your own messaging structures out of a shared memory segment and semiphores. Quite often I have found that message queues dont do exactly what people want them and do not always hold the correct data structures so building your own structures with a semiphore may be better off.