Results 1 to 2 of 2
Hi,
I am developing an API which will communicate with a daemon.
I am using POSIX message queues.
The API functions will send a message requesting data to the daemons ...
- 12-22-2011 #1Just Joined!
- Join Date
- Dec 2011
- Posts
- 1
Posix message queue help
Hi,
I am developing an API which will communicate with a daemon.
I am using POSIX message queues.
The API functions will send a message requesting data to the daemons message queue. The response from the daemon will be sent to another message queue which will be read by the api calling function and the then the api sends a response back.
My problem is that how to read the messages coming from the daemon. Here is example
api function A
{
send message to message daemon
poll message queue
}
api function B
{
send message to message daemon
poll message queue
}
Can the polling of the message queue just waiting for a certain message? api function a is waiting for its response and api function b is waiting for its response but it one function reads all the data then its a problem. What do you think is the best way to handle this?
thanks for your time
- 12-22-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Don't poll if you don't have to. Use mq_receive() instead, which will block until a message is available. Use mq_timedreceive() if you want to be unblocked when a timeout occurs. If both functions A and B have to run at the same time, then you may want a separate thread to handle the queue reading, and put the received data in a variable for the sending thread to fetch. That requires more work with mutexes or semaphores to protect the data structures involved.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote