Example mq_timedreceive

荒凉一梦 提交于 2020-07-22 03:49:28

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/30655148/example-mq-timedreceive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!