Real-Time Linux 229
/* Specify timeout as 10 seconds from now */
ts.tv_sec = time(NULL) + 10;
ts.tv_nsec = 0;
if (mq_timedsend(ds, text, SIZE,PRIOTITY, &ts) == -1){
if (errno == ETIMEDOUT){
printf("Timeout when waiting for message.");
return 0;
}
return -1;
}
/* receiving message */
if (mq_timedreceive(ds, new_text, SIZE, &prio, &ts) == -1){
if (errno == ETIMEDOUT){
printf("Timeout when waiting for message.");
return 0;
}
return -1;
}
Asynchronous Notification
The mq_notify function provides an asynchronous mechanism for processes
to receive notification that messages are available in a message queue rather
than synchronously blocking in
mq_receive or mq_timedreceive. This
interface is very useful for real-time applications. A process can call the
mq_notify ...