* @brief Receives a message from a message queue with a timeout. * @param id Message queue descriptor. * @param msg_ptr Pointer to the buffer where the received message will be stored. * @param msg_len Maximum size of the message buffer. * @param msg_prio Pointer to an unsigned integer where the priority of the received message will be stored. * @param abs_timeout Pointer to a str
| 281 | * and the function returns -1. |
| 282 | */ |
| 283 | ssize_t mq_timedreceive(mqd_t id, |
| 284 | char *msg_ptr, |
| 285 | size_t msg_len, |
| 286 | unsigned *msg_prio, |
| 287 | const struct timespec *abs_timeout) |
| 288 | { |
| 289 | rt_mq_t mq; |
| 290 | rt_err_t result; |
| 291 | int tick = 0; |
| 292 | struct mqueue_file *mq_file; |
| 293 | mq_file = fd_get(id)->vnode->data; |
| 294 | mq = (rt_mq_t)mq_file->data; |
| 295 | /* parameters check */ |
| 296 | if ((mq == RT_NULL) || (msg_ptr == RT_NULL)) |
| 297 | { |
| 298 | rt_set_errno(EINVAL); |
| 299 | return -1; |
| 300 | } |
| 301 | if (abs_timeout != RT_NULL) |
| 302 | tick = rt_timespec_to_tick(abs_timeout); |
| 303 | else |
| 304 | tick = RT_WAITING_FOREVER; |
| 305 | |
| 306 | result = rt_mq_recv_prio(mq, msg_ptr, msg_len, (rt_int32_t *)msg_prio, tick, RT_UNINTERRUPTIBLE); |
| 307 | |
| 308 | if (result >= 0) |
| 309 | return result; |
| 310 | |
| 311 | if (result == -RT_ETIMEOUT) |
| 312 | rt_set_errno(ETIMEDOUT); |
| 313 | else if (result == -RT_ERROR) |
| 314 | rt_set_errno(EMSGSIZE); |
| 315 | else |
| 316 | rt_set_errno(EBADMSG); |
| 317 | |
| 318 | return -1; |
| 319 | } |
| 320 | RTM_EXPORT(mq_timedreceive); |
| 321 | |
| 322 | /** |
no test coverage detected