Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C POSIX消息队列接收超时_C_Queue_Posix - Fatal编程技术网

C POSIX消息队列接收超时

C POSIX消息队列接收超时,c,queue,posix,C,Queue,Posix,如果没有收到消息,如何退出mq_receive。是否有可能给予超时。感谢您的时间。您可以使用mq_timedreceive函数。除了mq_timedreceive(),您还可以在使用mq_open()打开队列时设置O_非阻塞。Per: O_非块 确定mq_send()或mq_receive()是等待当前不可用的资源或消息,还是在errno设置为EAGAIN时失败;有关详细信息,请参见mq_发送和mq_接收 Per: 如果指定的消息队列为空,并且在与mqdes关联的消息队列描述中设置了O_NONB

如果没有收到消息,如何退出mq_receive。是否有可能给予超时。感谢您的时间。

您可以使用mq_timedreceive函数。

除了
mq_timedreceive()
,您还可以在使用
mq_open()
打开队列时设置
O_非阻塞
。Per:

O_非块
确定
mq_send()
mq_receive()
是等待当前不可用的资源或消息,还是在errno设置为
EAGAIN时失败;有关详细信息,请参见
mq_发送
mq_接收

Per:

如果指定的消息队列为空,并且在与
mqdes
关联的消息队列描述中设置了
O_NONBLOCK
,则不应从队列中删除任何消息,
mq_receive()
将返回错误


当我使用mq_timedreceive并在mq_open中设置O_非块时,如果未收到任何消息,它将返回错误。@EINSHEIM Yes,并且
errno
应设置为
EAGAIN
。这就是你知道没有留言的原因。谢谢安德鲁·亨勒。虽然这些超时不是单调的。。。所以在一个像嵌入式系统连接到GPS。。。这可能会导致有趣的行为
if((nbytes=mq_receive (qid_recv, (pchar_t)in_buffer, msg_buffer_size, NULL)) != -1) {
            printf("nbytes is %ld\n", nbytes);
}else{
     perror("recv_data");
     printf("nbytes is %ld\n", nbytes);