How to "reverse direction" of POSIX message queue in Linux?
I am trying to figure out how to "reverse" a single POSIX message queue to enable two-way communication between a client and server process while only using one POSIX message queue (i.e. only one memory segment at a time). The purpose of this is to cut memory overhead in half for IPC with many clients. This is, in essence, a half-duplex setup where two-way communication is supported, but messages can only flow in one direction at a time.
The standard approach is to use one queue for client -> server and one queue for server -> client as shown below (this is basically my current code). Client: Code:
... Code:
... Something along these lines: Client: Code:
open a single queue with mq_open for writing to the server Code:
open a single queue with mq_open for reading from client I am not open to using any other method of interprocess communication (such as shared memory, sysv queues, pipes, socket tcp/udp, etc.). |
What you are describing is very like a communication channel. Currently you have one that is asynchronous, what you WANT is one that is synchronous. You may need a handshake symbol or signal to release ownership of the channel, but that is easy enough to do.
I seem to recall doing that in assembler for RS-232 communications about half a century ago. The code may not apply, but the concepts certainly should. |
Well, you can simply destroy the queue and re-establish a new one (read at one end, write at the other, or vice versa) in response to an "over" message...
But honestly, your requirement makes less and less sense to me each time I think about it. You already have a full-duplex message queue that supports messages going in both directions. That means it already supports a protocol where the application layer (that would be your C code) knows when to send and when to receive, and signals that (to the other application) by sending an "over" message. You do not need the message queues themselves to enforce those restrictions. Is your actual technical problem trying to determine when the applications should send and when they should receive? |
Quote:
I am working with something along these lines (by the way, I'm using C++ not C): Code:
CommInterface class: Or should I not be using mq_notify at all? |
All times are GMT -5. The time now is 01:29 AM. |