1GETMSG(P)                  POSIX Programmer's Manual                 GETMSG(P)
2
3
4

NAME

6       getmsg, getpmsg - receive next message from a STREAMS file (STREAMS)
7

SYNOPSIS

9       #include <stropts.h>
10
11       int getmsg(int fildes, struct strbuf *restrict ctlptr,
12              struct strbuf *restrict dataptr, int *restrict flagsp);
13       int getpmsg(int fildes, struct strbuf *restrict ctlptr,
14              struct strbuf *restrict dataptr, int *restrict bandp,
15              int *restrict flagsp);
16
17

DESCRIPTION

19       The  getmsg() function shall retrieve the contents of a message located
20       at the head of the STREAM head read queue  associated  with  a  STREAMS
21       file  and place the contents into one or more buffers. The message con‐
22       tains either a data part, a control part, or both. The data and control
23       parts  of  the  message  shall  be  placed  into  separate  buffers, as
24       described below. The semantics of each part are defined by the origina‐
25       tor of the message.
26
27       The  getpmsg() function shall be equivalent to getmsg(), except that it
28       provides finer control over the  priority  of  the  messages  received.
29       Except  where  noted,  all  requirements  on  getmsg()  also pertain to
30       getpmsg().
31
32       The fildes argument specifies a file descriptor referencing a  STREAMS-
33       based file.
34
35       The  ctlptr  and dataptr arguments each point to a strbuf structure, in
36       which the buf member points to a buffer in which the  data  or  control
37       information  is to be placed, and the maxlen member indicates the maxi‐
38       mum number of bytes this buffer can hold. On  return,  the  len  member
39       shall  contain the number of bytes of data or control information actu‐
40       ally received. The len member shall be set to 0 if  there  is  a  zero-
41       length  control  or  data part and len shall be set to -1 if no data or
42       control information is present in the message.
43
44       When getmsg() is called, flagsp should point to an integer  that  indi‐
45       cates  the  type  of  message  the  process is able to receive. This is
46       described further below.
47
48       The ctlptr argument is used to hold the control part  of  the  message,
49       and dataptr is used to hold the data part of the message. If ctlptr (or
50       dataptr) is a null pointer or the maxlen member is -1, the control  (or
51       data)  part  of the message shall not be processed and shall be left on
52       the STREAM head read queue, and if the ctlptr (or  dataptr)  is  not  a
53       null  pointer, len shall be set to -1. If the maxlen member is set to 0
54       and there is a zero-length control (or  data)  part,  that  zero-length
55       part shall be removed from the read queue and len shall be set to 0. If
56       the maxlen member is set to 0 and there are more than 0 bytes  of  con‐
57       trol  (or data) information, that information shall be left on the read
58       queue and len shall be set to 0. If the maxlen  member  in  ctlptr  (or
59       dataptr) is less than the control (or data) part of the message, maxlen
60       bytes shall be retrieved.  In this case, the remainder of  the  message
61       shall be left on the STREAM head read queue and a non-zero return value
62       shall be provided.
63
64       By default, getmsg() shall process the first available message  on  the
65       STREAM  head read queue. However, a process may choose to retrieve only
66       high-priority messages by setting the integer pointed to by  flagsp  to
67       RS_HIPRI. In this case, getmsg() shall only process the next message if
68       it is a high-priority message. When the integer pointed to by flagsp is
69       0,  any  available message shall be retrieved. In this case, on return,
70       the integer pointed to by flagsp shall be set to RS_HIPRI  if  a  high-
71       priority message was retrieved, or 0 otherwise.
72
73       For getpmsg(), the flags are different. The flagsp argument points to a
74       bitmask with the following mutually-exclusive flags defined: MSG_HIPRI,
75       MSG_BAND,  and  MSG_ANY.   Like  getmsg(),  getpmsg() shall process the
76       first available message on the STREAM head read queue.  A  process  may
77       choose  to  retrieve only high-priority messages by setting the integer
78       pointed to by flagsp to MSG_HIPRI and the integer pointed to  by  bandp
79       to 0. In this case, getpmsg() shall only process the next message if it
80       is a high-priority message.  In a similar manner, a process may  choose
81       to  retrieve  a  message from a particular priority band by setting the
82       integer pointed to by flagsp to MSG_BAND and the integer pointed to  by
83       bandp  to  the priority band of interest. In this case, getpmsg() shall
84       only process the next message if it is in a priority band equal to,  or
85       greater  than, the integer pointed to by bandp, or if it is a high-pri‐
86       ority message. If a process wants to get  the  first  message  off  the
87       queue,  the  integer  pointed to by flagsp should be set to MSG_ANY and
88       the integer pointed to by bandp should be set to 0. On return,  if  the
89       message  retrieved  was a high-priority message, the integer pointed to
90       by flagsp shall be set to MSG_HIPRI and the integer pointed to by bandp
91       shall be set to 0. Otherwise, the integer pointed to by flagsp shall be
92       set to MSG_BAND and the integer pointed to by bandp shall be set to the
93       priority band of the message.
94
95       If  O_NONBLOCK  is  not set, getmsg() and getpmsg() shall block until a
96       message of the type specified by flagsp is available at  the  front  of
97       the  STREAM head read queue.  If O_NONBLOCK is set and a message of the
98       specified type is not present at the front of the read queue,  getmsg()
99       and getpmsg() shall fail and set errno to [EAGAIN].
100
101       If  a  hangup  occurs  on the STREAM from which messages are retrieved,
102       getmsg() and getpmsg() shall continue to operate normally, as described
103       above,  until  the  STREAM  head  read queue is empty. Thereafter, they
104       shall return 0 in the len members of ctlptr and dataptr.
105

RETURN VALUE

107       Upon successful completion, getmsg() and getpmsg() shall return a  non-
108       negative  value.  A  value  of 0 indicates that a full message was read
109       successfully. A return value of MORECTL  indicates  that  more  control
110       information  is waiting for retrieval. A return value of MOREDATA indi‐
111       cates that more data is waiting for retrieval.  A return value  of  the
112       bitwise-logical OR of MORECTL and MOREDATA indicates that both types of
113       information remain.  Subsequent  getmsg()  and  getpmsg()  calls  shall
114       retrieve  the remainder of the message. However, if a message of higher
115       priority has come in on the STREAM head read queue, the  next  call  to
116       getmsg()  or  getpmsg()  shall  retrieve  that  higher-priority message
117       before retrieving the remainder of the previous message.
118
119       If the high priority control part of the message is consumed, the  mes‐
120       sage  shall  be placed back on the queue as a normal message of band 0.
121       Subsequent getmsg() and getpmsg() calls shall retrieve the remainder of
122       the  message. If, however, a priority message arrives or already exists
123       on the STREAM head, the subsequent call to getmsg() or getpmsg()  shall
124       retrieve the higher-priority message before retrieving the remainder of
125       the message that was put back.
126
127       Upon failure, getmsg() and getpmsg() shall return -1 and set  errno  to
128       indicate the error.
129

ERRORS

131       The getmsg() and getpmsg() functions shall fail if:
132
133       EAGAIN The O_NONBLOCK flag is set and no messages are available.
134
135       EBADF  The  fildes  argument  is  not  a valid file descriptor open for
136              reading.
137
138       EBADMSG
139              The queued message to be read  is  not  valid  for  getmsg()  or
140              getpmsg() or a pending file descriptor is at the STREAM head.
141
142       EINTR  A signal was caught during getmsg() or getpmsg().
143
144       EINVAL An  illegal value was specified by flagsp, or the STREAM or mul‐
145              tiplexer referenced by fildes is linked (directly or indirectly)
146              downstream from a multiplexer.
147
148       ENOSTR A STREAM is not associated with fildes.
149
150
151       In  addition,  getmsg() and getpmsg() shall fail if the STREAM head had
152       processed an asynchronous error before the  call.  In  this  case,  the
153       value of errno does not reflect the result of getmsg() or getpmsg() but
154       reflects the prior error.
155
156       The following sections are informative.
157

EXAMPLES

159   Getting Any Message
160       In the following example, the value of fd is assumed  to  refer  to  an
161       open STREAMS file. The call to getmsg() retrieves any available message
162       on the associated STREAM-head read queue, returning  control  and  data
163       information  to  the buffers pointed to by ctrlbuf and databuf, respec‐
164       tively.
165
166
167              #include <stropts.h>
168              ...
169              int fd;
170              char ctrlbuf[128];
171              char databuf[512];
172              struct strbuf ctrl;
173              struct strbuf data;
174              int flags = 0;
175              int ret;
176
177
178              ctrl.buf = ctrlbuf;
179              ctrl.maxlen = sizeof(ctrlbuf);
180
181
182              data.buf = databuf;
183              data.maxlen = sizeof(databuf);
184
185
186              ret = getmsg (fd, &ctrl, &data, &flags);
187
188   Getting the First Message off the Queue
189       In the following example, the call to  getpmsg()  retrieves  the  first
190       available message on the associated STREAM-head read queue.
191
192
193              #include <stropts.h>
194              ...
195
196
197              int fd;
198              char ctrlbuf[128];
199              char databuf[512];
200              struct strbuf ctrl;
201              struct strbuf data;
202              int band = 0;
203              int flags = MSG_ANY;
204              int ret;
205
206
207              ctrl.buf = ctrlbuf;
208              ctrl.maxlen = sizeof(ctrlbuf);
209
210
211              data.buf = databuf;
212              data.maxlen = sizeof(databuf);
213
214
215              ret = getpmsg (fd, &ctrl, &data, &band, &flags);
216

APPLICATION USAGE

218       None.
219

RATIONALE

221       None.
222

FUTURE DIRECTIONS

224       None.
225

SEE ALSO

227       STREAMS  ,  poll() , putmsg() , read() , write() , the Base Definitions
228       volume of IEEE Std 1003.1-2001, <stropts.h>
229
231       Portions of this text are reprinted and reproduced in  electronic  form
232       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
233       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
234       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
235       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
236       event of any discrepancy between this version and the original IEEE and
237       The Open Group Standard, the original IEEE and The Open Group  Standard
238       is  the  referee document. The original Standard can be obtained online
239       at http://www.opengroup.org/unix/online.html .
240
241
242
243IEEE/The Open Group                  2003                            GETMSG(P)
Impressum