MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / mq_timedreceive

Function mq_timedreceive

components/libc/posix/ipc/mqueue.c:283–319  ·  view source on GitHub ↗

* @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

Source from the content-addressed store, hash-verified

281 * and the function returns -1.
282 */
283ssize_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}
320RTM_EXPORT(mq_timedreceive);
321
322/**

Callers 1

sys_mq_timedreceiveFunction · 0.85

Calls 4

rt_set_errnoFunction · 0.85
rt_timespec_to_tickFunction · 0.85
rt_mq_recv_prioFunction · 0.85
fd_getFunction · 0.50

Tested by

no test coverage detected