示例 mq_timedreceive [英] Example mq_timedreceive

查看:107
本文介绍了示例 mq_timedreceive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到如何使用 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);

我希望 timereceive 等待的时间不要超过 20 秒.

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

非常感谢.

推荐答案

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 ) )  {
  ...
}

此处查看完整说明

这篇关于示例 mq_timedreceive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆