mqueue.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * Amazon FreeRTOS POSIX V1.1.0
  3. * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  17. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  19. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * http://aws.amazon.com/freertos
  23. * http://www.FreeRTOS.org
  24. */
  25. /**
  26. * @file mqueue.h
  27. * @brief Message queues.
  28. *
  29. * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html
  30. */
  31. #ifndef _FREERTOS_POSIX_MQUEUE_H_
  32. #define _FREERTOS_POSIX_MQUEUE_H_
  33. /* FreeRTOS+POSIX includes. */
  34. #include "FreeRTOS_POSIX/time.h"
  35. /**
  36. * @brief Message queue descriptor.
  37. */
  38. typedef void * mqd_t;
  39. /**
  40. * @brief Message queue attributes.
  41. */
  42. struct mq_attr
  43. {
  44. long mq_flags; /**< Message queue flags. */
  45. long mq_maxmsg; /**< Maximum number of messages. */
  46. long mq_msgsize; /**< Maximum message size. */
  47. long mq_curmsgs; /**< Number of messages currently queued. */
  48. };
  49. /**
  50. * @brief Close a message queue.
  51. *
  52. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html
  53. *
  54. * @retval 0 - Upon successful completion
  55. * @retval -1 - A error occurred. errno is also set.
  56. *
  57. * @sideeffect Possible errno values
  58. * <br>
  59. * EBADF - The mqdes argument is not a valid message queue descriptor.
  60. */
  61. int mq_close( mqd_t mqdes );
  62. /**
  63. * @brief Get message queue attributes.
  64. *
  65. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html
  66. *
  67. * @retval 0 - Upon successful completion
  68. * @retval -1 - A error occurred. errno is also set.
  69. *
  70. * @sideeffect Possible errno values
  71. * <br>
  72. * DBADF - The mqdes argument is not a valid message queue descriptor.
  73. */
  74. int mq_getattr( mqd_t mqdes,
  75. struct mq_attr * mqstat );
  76. /**
  77. * @brief Open a message queue.
  78. *
  79. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html
  80. *
  81. * @note Supported name pattern: leading &lt;slash&gt; character in name is always required;
  82. * the maximum length (excluding null-terminator) of the name argument can be NAME_MAX.
  83. * The default value of NAME_MAX in FreeRTOS_POSIX_portable_default.h is 64, which can be
  84. * overwritten by user.
  85. * @note mode argument is not supported.
  86. * @note Supported oflags: O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
  87. *
  88. * @retval Message queue descriptor -- Upon successful completion
  89. * @retval (mqd_t) - 1 -- An error occurred. errno is also set.
  90. *
  91. * @sideeffect Possible errno values
  92. * <br>
  93. * EINVAL - name argument is invalid (not following name pattern),
  94. * OR if O_CREAT is specified in oflag with attr argument not NULL and either mq_maxmsg or mq_msgsize is equal to or less than zero,
  95. * OR either O_CREAT or O_EXCL is not set and a queue with the same name is unlinked but pending to be removed.
  96. * <br>
  97. * EEXIST - O_CREAT and O_EXCL are set and the named message queue already exists.
  98. * <br>
  99. * ENOSPC - There is insufficient space for the creation of the new message queue.
  100. * <br>
  101. * ENOENT - O_CREAT is not set and the named message queue does not exist.
  102. */
  103. mqd_t mq_open( const char * name,
  104. int oflag,
  105. mode_t mode,
  106. struct mq_attr * attr );
  107. /**
  108. * @brief Receive a message from a message queue.
  109. *
  110. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html
  111. *
  112. * @note msg_prio argument is not supported. Messages are not checked for corruption.
  113. *
  114. * @retval The length of the selected message in bytes - Upon successful completion.
  115. * The message is removed from the queue
  116. * @retval -1 - An error occurred. errno is also set.
  117. *
  118. * @sideeffect Possible errno values
  119. * <br>
  120. * EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
  121. * <br>
  122. * EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
  123. * <br>
  124. * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
  125. * but no message arrived on the queue before the specified timeout expired.
  126. * <br>
  127. * EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
  128. */
  129. ssize_t mq_receive( mqd_t mqdes,
  130. char * msg_ptr,
  131. size_t msg_len,
  132. unsigned int * msg_prio );
  133. /**
  134. * @brief Send a message to a message queue.
  135. *
  136. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html
  137. *
  138. * @note msg_prio argument is not supported.
  139. *
  140. * @retval 0 - Upon successful completion.
  141. * @retval -1 - An error occurred. errno is also set.
  142. *
  143. * @sideeffect Possible errno values
  144. * <br>
  145. * EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
  146. * <br>
  147. * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
  148. * OR insufficient memory for the message to be sent.
  149. * <br>
  150. * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
  151. * but the timeout expired before the message could be added to the queue.
  152. * <br>
  153. * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
  154. * and the specified message queue is full.
  155. */
  156. int mq_send( mqd_t mqdes,
  157. const char * msg_ptr,
  158. size_t msg_len,
  159. unsigned msg_prio );
  160. /**
  161. * @brief Receive a message from a message queue with timeout.
  162. *
  163. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedreceive.html
  164. *
  165. * @note msg_prio argument is not supported. Messages are not checked for corruption.
  166. *
  167. * @retval The length of the selected message in bytes - Upon successful completion.
  168. * The message is removed from the queue
  169. * @retval -1 - An error occurred. errno is also set.
  170. *
  171. * @sideeffect Possible errno values
  172. * <br>
  173. * EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
  174. * <br>
  175. * EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
  176. * <br>
  177. * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field value
  178. * less than zero or greater than or equal to 1000 million.
  179. * <br>
  180. * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
  181. * but no message arrived on the queue before the specified timeout expired.
  182. * <br>
  183. * EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
  184. */
  185. ssize_t mq_timedreceive( mqd_t mqdes,
  186. char * msg_ptr,
  187. size_t msg_len,
  188. unsigned * msg_prio,
  189. const struct timespec * abstime );
  190. /**
  191. * @brief Send a message to a message queue with timeout.
  192. *
  193. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedsend.html
  194. *
  195. * @note msg_prio argument is not supported.
  196. *
  197. * @retval 0 - Upon successful completion.
  198. * @retval -1 - An error occurred. errno is also set.
  199. *
  200. * @sideeffect Possible errno values
  201. * <br>
  202. * EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
  203. * <br>
  204. * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
  205. * OR insufficient memory for the message to be sent.
  206. * <br>
  207. * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field
  208. * value less than zero or greater than or equal to 1000 million.
  209. * <br>
  210. * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
  211. * but the timeout expired before the message could be added to the queue.
  212. * <br>
  213. * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
  214. * and the specified message queue is full.
  215. */
  216. int mq_timedsend( mqd_t mqdes,
  217. const char * msg_ptr,
  218. size_t msg_len,
  219. unsigned msg_prio,
  220. const struct timespec * abstime );
  221. /**
  222. * @brief Remove a message queue.
  223. *
  224. * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html
  225. *
  226. * @retval 0 - Upon successful completion.
  227. * @retval -1 - An error occurred. errno is also set.
  228. *
  229. * @sideeffect Possible errno values
  230. * <br>
  231. * EINVAL - name argument is invalid. Refer to requirements on name argument in mq_open().
  232. * <br>
  233. * ENOENT - The named message queue does not exist.
  234. */
  235. int mq_unlink( const char * name );
  236. #endif /* ifndef _FREERTOS_POSIX_MQUEUE_H_ */