* @brief Sends a message to a message queue. * @param id Message queue descriptor. * @param msg_ptr Pointer to the buffer containing the message to be sent. * @param msg_len Size of the message to be sent. * @param msg_prio Priority of the message to be sent. * @return Upon successful completion, returns 0; * otherwise, returns -1 and sets errno to indicate the error. *
| 233 | * and the function returns -1. |
| 234 | */ |
| 235 | int mq_send(mqd_t id, const char *msg_ptr, size_t msg_len, unsigned msg_prio) |
| 236 | { |
| 237 | rt_mq_t mq; |
| 238 | rt_err_t result; |
| 239 | struct mqueue_file *mq_file; |
| 240 | mq_file = fd_get(id)->vnode->data; |
| 241 | mq = (rt_mq_t)mq_file->data; |
| 242 | |
| 243 | if ((mq == RT_NULL) || (msg_ptr == RT_NULL)) |
| 244 | { |
| 245 | rt_set_errno(EINVAL); |
| 246 | return -1; |
| 247 | } |
| 248 | result = rt_mq_send_wait_prio(mq, (void *)msg_ptr, msg_len, msg_prio, 0, RT_UNINTERRUPTIBLE); |
| 249 | if (result == RT_EOK) |
| 250 | return 0; |
| 251 | |
| 252 | rt_set_errno(EBADF); |
| 253 | |
| 254 | return -1; |
| 255 | } |
| 256 | RTM_EXPORT(mq_send); |
| 257 | |
| 258 | /** |
no test coverage detected