Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example mq_timedreceive

I can not find how to work properly with mq_timedreceive, can anyone give me an example?

ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
                   size_t msg_len, unsigned *msg_prio,
                   const struct timespec *abs_timeout);

I want timereceive to do not spent more than 20 seconds waiting.

Thank you very much.

like image 548
difegui Avatar asked Sep 10 '26 02:09

difegui


1 Answers

struct   timespec tm;

clock_gettime(CLOCK_REALTIME, &tm);
tm.tv_sec += 20;  // Set for 20 seconds
if( 0 > mq_timedreceive( fd, buf, 4096, NULL, &tm ) )  {
  ...
}

Take a look at the full description here

like image 84
rost0031 Avatar answered Sep 11 '26 16:09

rost0031