发送到mq_timedreceive的timespec设置为20秒。经过20秒后,errno返回资源暂时不可用(EAGAIN)。此外,这会发送一个消息并导致进程崩溃。我期望发生的是一个ETIMEDOUT响应,并且我的代码将继续执行。我确保队列不与O_NONBLOCK一起使用,因此应该没有理由进行EAGAIN

event_type get_event_timed(mqd_t channel, struct timespec ts) {
//get timed touch event from devi-atmel-mxt
ssize_t ret = -1;
char Buffer[ASYNC_BUFFER_SIZE] = {0};

event_type *event;

//mq_monotonic will block for duration specfifed by timespec
//will return -1 && ETIMEDOUT if no event withing duration
ret = mq_timedreceive(channel, Buffer, ASYNC_BUFFER_SIZE, NULL, &ts);
if ((-1 == ret) && (errno == ETIMEDOUT)) {
    slogf(_SLOGC_INPUT, _SLOG_ERROR, "[ASYNC_LOGGER] %s TIMEDOUT\n", __func__);
    //return TIMEDOUT
    *event = TIMEDOUT;
}
else if (-1 == ret) {
    slogf(_SLOGC_INPUT, _SLOG_ERROR, "[ASYNC_LOGGER] %s error: %s\n", __func__, strerror(errno));
    //return ERROR
    *event = ERROR;
}
else {
    //printf("mq_recieve sucess\n");
    slogf(_SLOGC_INPUT, _SLOG_ERROR, "[ASYNC_LOGGER] get_event_timed: mq_recieve success\n");
    //casting buffer into event_type
    event = (event_type *)Buffer;
}
slogf(_SLOGC_INPUT, _SLOG_ERROR, "[ASYNC_LOGGER] %s buffer is: %d\n", __func__, *event);
return *event;


}

最佳答案

这是QNX中的已知错误。由于队列同时也清空,因此mq无法在ETIMEDOUT和O_NONBLOCK之间知道。

关于c - mq_timedreceive报告EAGAIN错误,未设置O_NONBLOCK,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43127708/

10-12 03:00