1 .\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
2 .TH "GETMSG" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
5 getmsg, getpmsg \- receive next message from a STREAMS file (\fBSTREAMS\fP)
8 \fB#include <stropts.h>
11 int getmsg(int\fP \fIfildes\fP\fB, struct strbuf *restrict\fP \fIctlptr\fP\fB,
13 \ \ \ \ \ \ struct strbuf *restrict\fP \fIdataptr\fP\fB, int *restrict\fP
16 int getpmsg(int\fP \fIfildes\fP\fB, struct strbuf *restrict\fP \fIctlptr\fP\fB,
18 \ \ \ \ \ \ struct strbuf *restrict\fP \fIdataptr\fP\fB, int *restrict\fP
21 \ \ \ \ \ \ int *restrict\fP \fIflagsp\fP\fB); \fP
27 The \fIgetmsg\fP() function shall retrieve the contents of a message
28 located at the head of the STREAM head read queue
29 associated with a STREAMS file and place the contents into one or
30 more buffers. The message contains either a data part, a control
31 part, or both. The data and control parts of the message shall be
32 placed into separate buffers, as described below. The semantics
33 of each part are defined by the originator of the message.
35 The \fIgetpmsg\fP() function shall be equivalent to \fIgetmsg\fP(),
36 except that it provides finer control over the priority of
37 the messages received. Except where noted, all requirements on \fIgetmsg\fP()
38 also pertain to \fIgetpmsg\fP().
40 The \fIfildes\fP argument specifies a file descriptor referencing
43 The \fIctlptr\fP and \fIdataptr\fP arguments each point to a \fBstrbuf\fP
44 structure, in which the \fIbuf\fP member points to
45 a buffer in which the data or control information is to be placed,
46 and the \fImaxlen\fP member indicates the maximum number of
47 bytes this buffer can hold. On return, the \fIlen\fP member shall
48 contain the number of bytes of data or control information
49 actually received. The \fIlen\fP member shall be set to 0 if there
50 is a zero-length control or data part and \fIlen\fP shall be
51 set to -1 if no data or control information is present in the message.
53 When \fIgetmsg\fP() is called, \fIflagsp\fP should point to an integer
54 that indicates the type of message the process is able
55 to receive. This is described further below.
57 The \fIctlptr\fP argument is used to hold the control part of the
58 message, and \fIdataptr\fP is used to hold the data part of
59 the message. If \fIctlptr\fP (or \fIdataptr\fP) is a null pointer
60 or the \fImaxlen\fP member is -1, the control (or data) part
61 of the message shall not be processed and shall be left on the STREAM
62 head read queue, and if the \fIctlptr\fP (or \fIdataptr\fP)
63 is not a null pointer, \fIlen\fP shall be set to -1. If the \fImaxlen\fP
64 member is set to 0 and there is a zero-length control
65 (or data) part, that zero-length part shall be removed from the read
66 queue and \fIlen\fP shall be set to 0. If the \fImaxlen\fP
67 member is set to 0 and there are more than 0 bytes of control (or
68 data) information, that information shall be left on the read
69 queue and \fIlen\fP shall be set to 0. If the \fImaxlen\fP member
70 in \fIctlptr\fP (or \fIdataptr\fP) is less than the control
71 (or data) part of the message, \fImaxlen\fP bytes shall be retrieved.
72 In this case, the remainder of the message shall be left on
73 the STREAM head read queue and a non-zero return value shall be provided.
75 By default, \fIgetmsg\fP() shall process the first available message
76 on the STREAM head read queue. However, a process may
77 choose to retrieve only high-priority messages by setting the integer
78 pointed to by \fIflagsp\fP to RS_HIPRI. In this case,
79 \fIgetmsg\fP() shall only process the next message if it is a high-priority
80 message. When the integer pointed to by \fIflagsp\fP
81 is 0, any available message shall be retrieved. In this case, on return,
82 the integer pointed to by \fIflagsp\fP shall be set to
83 RS_HIPRI if a high-priority message was retrieved, or 0 otherwise.
85 For \fIgetpmsg\fP(), the flags are different. The \fIflagsp\fP argument
86 points to a bitmask with the following
87 mutually-exclusive flags defined: MSG_HIPRI, MSG_BAND, and MSG_ANY.
88 Like \fIgetmsg\fP(), \fIgetpmsg\fP() shall process the first
89 available message on the STREAM head read queue. A process may choose
90 to retrieve only high-priority messages by setting the
91 integer pointed to by \fIflagsp\fP to MSG_HIPRI and the integer pointed
92 to by \fIbandp\fP to 0. In this case, \fIgetpmsg\fP()
93 shall only process the next message if it is a high-priority message.
94 In a similar manner, a process may choose to retrieve a
95 message from a particular priority band by setting the integer pointed
96 to by \fIflagsp\fP to MSG_BAND and the integer pointed to
97 by \fIbandp\fP to the priority band of interest. In this case, \fIgetpmsg\fP()
98 shall only process the next message if it is in a
99 priority band equal to, or greater than, the integer pointed to by
100 \fIbandp\fP, or if it is a high-priority message. If a process
101 wants to get the first message off the queue, the integer pointed
102 to by \fIflagsp\fP should be set to MSG_ANY and the integer
103 pointed to by \fIbandp\fP should be set to 0. On return, if the message
104 retrieved was a high-priority message, the integer pointed
105 to by \fIflagsp\fP shall be set to MSG_HIPRI and the integer pointed
106 to by \fIbandp\fP shall be set to 0. Otherwise, the integer
107 pointed to by \fIflagsp\fP shall be set to MSG_BAND and the integer
108 pointed to by \fIbandp\fP shall be set to the priority band
111 If O_NONBLOCK is not set, \fIgetmsg\fP() and \fIgetpmsg\fP() shall
112 block until a message of the type specified by
113 \fIflagsp\fP is available at the front of the STREAM head read queue.
114 If O_NONBLOCK is set and a message of the specified type is
115 not present at the front of the read queue, \fIgetmsg\fP() and \fIgetpmsg\fP()
116 shall fail and set \fIerrno\fP to [EAGAIN].
118 If a hangup occurs on the STREAM from which messages are retrieved,
119 \fIgetmsg\fP() and \fIgetpmsg\fP() shall continue to
120 operate normally, as described above, until the STREAM head read queue
121 is empty. Thereafter, they shall return 0 in the \fIlen\fP
122 members of \fIctlptr\fP and \fIdataptr\fP.
125 Upon successful completion, \fIgetmsg\fP() and \fIgetpmsg\fP() shall
126 return a non-negative value. A value of 0 indicates that
127 a full message was read successfully. A return value of MORECTL indicates
128 that more control information is waiting for retrieval. A
129 return value of MOREDATA indicates that more data is waiting for retrieval.
130 A return value of the bitwise-logical OR of MORECTL and
131 MOREDATA indicates that both types of information remain. Subsequent
132 \fIgetmsg\fP() and \fIgetpmsg\fP() calls shall retrieve the
133 remainder of the message. However, if a message of higher priority
134 has come in on the STREAM head read queue, the next call to
135 \fIgetmsg\fP() or \fIgetpmsg\fP() shall retrieve that higher-priority
136 message before retrieving the remainder of the previous
139 If the high priority control part of the message is consumed, the
140 message shall be placed back on the queue as a normal message
141 of band 0. Subsequent \fIgetmsg\fP() and \fIgetpmsg\fP() calls shall
142 retrieve the remainder of the message. If, however, a
143 priority message arrives or already exists on the STREAM head, the
144 subsequent call to \fIgetmsg\fP() or \fIgetpmsg\fP() shall
145 retrieve the higher-priority message before retrieving the remainder
146 of the message that was put back.
148 Upon failure, \fIgetmsg\fP() and \fIgetpmsg\fP() shall return -1 and
149 set \fIerrno\fP to indicate the error.
152 The \fIgetmsg\fP() and \fIgetpmsg\fP() functions shall fail if:
155 The O_NONBLOCK flag is set and no messages are available.
158 The \fIfildes\fP argument is not a valid file descriptor open for
162 The queued message to be read is not valid for \fIgetmsg\fP() or \fIgetpmsg\fP()
163 or a pending file descriptor is at the
167 A signal was caught during \fIgetmsg\fP() or \fIgetpmsg\fP().
170 An illegal value was specified by \fIflagsp\fP, or the STREAM or multiplexer
171 referenced by \fIfildes\fP is linked (directly
172 or indirectly) downstream from a multiplexer.
175 A STREAM is not associated with \fIfildes\fP.
178 In addition, \fIgetmsg\fP() and \fIgetpmsg\fP() shall fail if the
179 STREAM head had processed an asynchronous error before the
180 call. In this case, the value of \fIerrno\fP does not reflect the
181 result of \fIgetmsg\fP() or \fIgetpmsg\fP() but reflects the
184 \fIThe following sections are informative.\fP
186 .SS Getting Any Message
188 In the following example, the value of \fIfd\fP is assumed to refer
189 to an open STREAMS file. The call to \fIgetmsg\fP()
190 retrieves any available message on the associated STREAM-head read
191 queue, returning control and data information to the buffers
192 pointed to by \fIctrlbuf\fP and \fIdatabuf\fP, respectively.
197 \fB#include <stropts.h>
209 ctrl.maxlen = sizeof(ctrlbuf);
213 data.maxlen = sizeof(databuf);
216 ret = getmsg (fd, &ctrl, &data, &flags);
220 .SS Getting the First Message off the Queue
222 In the following example, the call to \fIgetpmsg\fP() retrieves the
223 first available message on the associated STREAM-head read
229 \fB#include <stropts.h>
244 ctrl.maxlen = sizeof(ctrlbuf);
248 data.maxlen = sizeof(databuf);
251 ret = getpmsg (fd, &ctrl, &data, &band, &flags);
255 .SH APPLICATION USAGE
261 .SH FUTURE DIRECTIONS
266 \fISTREAMS\fP , \fIpoll\fP() , \fIputmsg\fP() , \fIread\fP() , \fIwrite\fP()
268 Definitions volume of IEEE\ Std\ 1003.1-2001, \fI<stropts.h>\fP
270 Portions of this text are reprinted and reproduced in electronic form
271 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
272 -- Portable Operating System Interface (POSIX), The Open Group Base
273 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
274 Electrical and Electronics Engineers, Inc and The Open Group. In the
275 event of any discrepancy between this version and the original IEEE and
276 The Open Group Standard, the original IEEE and The Open Group Standard
277 is the referee document. The original Standard can be obtained online at
278 http://www.opengroup.org/unix/online.html .