POSIX 消息队列接收超时
POSIX Message Queue Receive Timeout
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);
如果没有消息,如何从 mq_receive 退出 received.Is 有没有可能 timeout.Thanks 您的时间。
您可以使用mq_timedreceive函数。
除了mq_timedreceive()
,你还可以在mq_open()
打开队列时设置O_NONBLOCK
。每 the mq_open()
documentation:
O_NONBLOCK
Determines whether an mq_send()
or mq_receive()
waits for resources or messages that are not currently available, or fails with errno set to EAGAIN
; see mq_send
and mq_receive
for details.
根据 the mq_receive()
documentation:
If the specified message queue is empty and O_NONBLOCK
is set in the message queue description associated with mqdes
, no message shall be removed from the queue, and mq_receive()
shall return an error.
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);
如果没有消息,如何从 mq_receive 退出 received.Is 有没有可能 timeout.Thanks 您的时间。
您可以使用mq_timedreceive函数。
除了mq_timedreceive()
,你还可以在mq_open()
打开队列时设置O_NONBLOCK
。每 the mq_open()
documentation:
O_NONBLOCK
Determines whether anmq_send()
ormq_receive()
waits for resources or messages that are not currently available, or fails with errno set toEAGAIN
; seemq_send
andmq_receive
for details.
根据 the mq_receive()
documentation:
If the specified message queue is empty and
O_NONBLOCK
is set in the message queue description associated withmqdes
, no message shall be removed from the queue, andmq_receive()
shall return an error.