logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

msgrcv.3p (7292B)


  1. '\" et
  2. .TH MSGRCV "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. msgrcv
  12. \(em XSI message receive operation
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <sys/msg.h>
  17. .P
  18. ssize_t msgrcv(int \fImsqid\fP, void *\fImsgp\fP, size_t \fImsgsz\fP, long \fImsgtyp\fP,
  19. int \fImsgflg\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fImsgrcv\fR()
  24. function operates on XSI message queues (see the Base Definitions volume of POSIX.1\(hy2017,
  25. .IR "Section 3.226" ", " "Message Queue").
  26. It is unspecified whether this function interoperates with the
  27. realtime interprocess communication facilities defined in
  28. .IR "Section 2.8" ", " "Realtime".
  29. .P
  30. The
  31. \fImsgrcv\fR()
  32. function shall read a message from the queue associated with the message
  33. queue identifier specified by
  34. .IR msqid
  35. and place it in the user-defined buffer pointed to by
  36. .IR msgp .
  37. .P
  38. The application shall ensure that the argument
  39. .IR msgp
  40. points to a user-defined buffer that contains first a field of type
  41. .BR long
  42. specifying the type of the message, and then a data portion that holds
  43. the data bytes of the message. The structure below is an example of
  44. what this user-defined buffer might look like:
  45. .sp
  46. .RS 4
  47. .nf
  48. struct mymsg {
  49. long mtype; /* Message type. */
  50. char mtext[1]; /* Message text. */
  51. }
  52. .fi
  53. .P
  54. .RE
  55. .P
  56. The structure member
  57. .IR mtype
  58. is the received message's type as specified by the sending process.
  59. .P
  60. The structure member
  61. .IR mtext
  62. is the text of the message.
  63. .P
  64. The argument
  65. .IR msgsz
  66. specifies the size in bytes of
  67. .IR mtext .
  68. The received message shall be truncated to
  69. .IR msgsz
  70. bytes if it is larger than
  71. .IR msgsz
  72. and (\fImsgflg\fP & MSG_NOERROR) is non-zero.
  73. The truncated part of the message shall be lost and no indication of
  74. the truncation shall be given to the calling process.
  75. .P
  76. If the value of
  77. .IR msgsz
  78. is greater than
  79. {SSIZE_MAX},
  80. the result is implementation-defined.
  81. .P
  82. The argument
  83. .IR msgtyp
  84. specifies the type of message requested as follows:
  85. .IP " *" 4
  86. If
  87. .IR msgtyp
  88. is 0, the first message on the queue shall be received.
  89. .IP " *" 4
  90. If
  91. .IR msgtyp
  92. is greater than 0, the first message of type
  93. .IR msgtyp
  94. shall be received.
  95. .IP " *" 4
  96. If
  97. .IR msgtyp
  98. is less than 0, the first message of the lowest type that is less than
  99. or equal to the absolute value of
  100. .IR msgtyp
  101. shall be received.
  102. .P
  103. The argument
  104. .IR msgflg
  105. specifies the action to be taken if a message of the desired type is
  106. not on the queue. These are as follows:
  107. .IP " *" 4
  108. If (\fImsgflg\fP & IPC_NOWAIT)
  109. is non-zero, the calling thread shall return immediately with a return
  110. value of \-1 and
  111. .IR errno
  112. set to
  113. .BR [ENOMSG] .
  114. .IP " *" 4
  115. If (\fImsgflg\fP & IPC_NOWAIT) is 0, the calling thread shall suspend
  116. execution until one of the following occurs:
  117. .RS 4
  118. .IP -- 4
  119. A message of the desired type is placed on the queue.
  120. .IP -- 4
  121. The message queue identifier
  122. .IR msqid
  123. is removed from the system; when this occurs,
  124. .IR errno
  125. shall be set to
  126. .BR [EIDRM]
  127. and \-1 shall be returned.
  128. .IP -- 4
  129. The calling thread receives a signal that is to be caught; in this case
  130. a message is not received and the calling thread resumes execution in
  131. the manner prescribed in
  132. .IR "\fIsigaction\fR\^(\|)".
  133. .RE
  134. .P
  135. Upon successful completion, the following actions are taken with
  136. respect to the data structure associated with
  137. .IR msqid :
  138. .IP " *" 4
  139. .BR msg_qnum
  140. shall be decremented by 1.
  141. .IP " *" 4
  142. .BR msg_lrpid
  143. shall be set to the process ID of the calling process.
  144. .IP " *" 4
  145. .BR msg_rtime
  146. shall be set to the current time, as described in
  147. .IR "Section 2.7.1" ", " "IPC General Description".
  148. .SH "RETURN VALUE"
  149. Upon successful completion,
  150. \fImsgrcv\fR()
  151. shall return a value equal to the number of bytes actually placed
  152. into the buffer
  153. .IR mtext .
  154. Otherwise, no message shall be received,
  155. \fImsgrcv\fR()
  156. shall return \-1, and
  157. .IR errno
  158. shall be set to indicate the error.
  159. .SH ERRORS
  160. The
  161. \fImsgrcv\fR()
  162. function shall fail if:
  163. .TP
  164. .BR E2BIG
  165. The value of
  166. .IR mtext
  167. is greater than
  168. .IR msgsz
  169. and (\fImsgflg\fP & MSG_NOERROR) is 0.
  170. .TP
  171. .BR EACCES
  172. Operation permission is denied to the calling process; see
  173. .IR "Section 2.7" ", " "XSI Interprocess Communication".
  174. .TP
  175. .BR EIDRM
  176. The message queue identifier
  177. .IR msqid
  178. is removed from the system.
  179. .TP
  180. .BR EINTR
  181. The
  182. \fImsgrcv\fR()
  183. function was interrupted by a signal.
  184. .TP
  185. .BR EINVAL
  186. .IR msqid
  187. is not a valid message queue identifier.
  188. .TP
  189. .BR ENOMSG
  190. The queue does not contain a message of the desired type and
  191. (\fImsgflg\fP & IPC_NOWAIT) is non-zero.
  192. .LP
  193. .IR "The following sections are informative."
  194. .SH EXAMPLES
  195. .SS "Receiving a Message"
  196. .P
  197. The following example receives the first message on the queue (based on
  198. the value of the
  199. .IR msgtyp
  200. argument, 0). The queue is identified by the
  201. .IR msqid
  202. argument (assuming that the value has previously been set). This call
  203. specifies that an error should be reported if no message is available,
  204. but not if the message is too large. The message size is calculated
  205. directly using the
  206. .IR sizeof
  207. operator.
  208. .sp
  209. .RS 4
  210. .nf
  211. #include <sys/msg.h>
  212. \&...
  213. int result;
  214. int msqid;
  215. struct message {
  216. long type;
  217. char text[20];
  218. } msg;
  219. long msgtyp = 0;
  220. \&...
  221. result = msgrcv(msqid, (void *) &msg, sizeof(msg.text),
  222. msgtyp, MSG_NOERROR | IPC_NOWAIT);
  223. .fi
  224. .P
  225. .RE
  226. .SH "APPLICATION USAGE"
  227. The POSIX Realtime Extension defines alternative interfaces for interprocess communication
  228. (IPC). Application developers who need to use IPC should design their
  229. applications so that modules using the IPC routines described in
  230. .IR "Section 2.7" ", " "XSI Interprocess Communication"
  231. can be easily modified to use the alternative interfaces.
  232. .SH RATIONALE
  233. None.
  234. .SH "FUTURE DIRECTIONS"
  235. None.
  236. .SH "SEE ALSO"
  237. .IR "Section 2.7" ", " "XSI Interprocess Communication",
  238. .IR "Section 2.8" ", " "Realtime",
  239. .IR "\fImq_close\fR\^(\|)",
  240. .IR "\fImq_getattr\fR\^(\|)",
  241. .IR "\fImq_notify\fR\^(\|)",
  242. .IR "\fImq_open\fR\^(\|)",
  243. .IR "\fImq_receive\fR\^(\|)",
  244. .IR "\fImq_send\fR\^(\|)",
  245. .IR "\fImq_setattr\fR\^(\|)",
  246. .IR "\fImq_unlink\fR\^(\|)",
  247. .IR "\fImsgctl\fR\^(\|)",
  248. .IR "\fImsgget\fR\^(\|)",
  249. .IR "\fImsgsnd\fR\^(\|)",
  250. .IR "\fIsigaction\fR\^(\|)"
  251. .P
  252. The Base Definitions volume of POSIX.1\(hy2017,
  253. .IR "Section 3.226" ", " "Message Queue",
  254. .IR "\fB<sys_msg.h>\fP"
  255. .\"
  256. .SH COPYRIGHT
  257. Portions of this text are reprinted and reproduced in electronic form
  258. from IEEE Std 1003.1-2017, Standard for Information Technology
  259. -- Portable Operating System Interface (POSIX), The Open Group Base
  260. Specifications Issue 7, 2018 Edition,
  261. Copyright (C) 2018 by the Institute of
  262. Electrical and Electronics Engineers, Inc and The Open Group.
  263. In the event of any discrepancy between this version and the original IEEE and
  264. The Open Group Standard, the original IEEE and The Open Group Standard
  265. is the referee document. The original Standard can be obtained online at
  266. http://www.opengroup.org/unix/online.html .
  267. .PP
  268. Any typographical or formatting errors that appear
  269. in this page are most likely
  270. to have been introduced during the conversion of the source files to
  271. man page format. To report such errors, see
  272. https://www.kernel.org/doc/man-pages/reporting_bugs.html .