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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       getmsg, getpmsg — receive next message from a STREAMS file (STREAMS)
13

SYNOPSIS

15       #include <stropts.h>
16
17       int getmsg(int fildes, struct strbuf *restrict ctlptr,
18           struct strbuf *restrict dataptr, int *restrict flagsp);
19       int getpmsg(int fildes, struct strbuf *restrict ctlptr,
20           struct strbuf *restrict dataptr, int *restrict bandp,
21           int *restrict flagsp);
22

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

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

APPLICATION USAGE

215       None.
216

RATIONALE

218       None.
219

FUTURE DIRECTIONS

221       The getmsg() and getpmsg() functions may be removed in  a  future  ver‐
222       sion.
223

SEE ALSO

225       Section 2.6, STREAMS, poll(), putmsg(), read(), write()
226
227       The Base Definitions volume of POSIX.1‐2017, <stropts.h>
228
230       Portions  of  this text are reprinted and reproduced in electronic form
231       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
232       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
233       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
234       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
235       event of any discrepancy between this version and the original IEEE and
236       The  Open Group Standard, the original IEEE and The Open Group Standard
237       is the referee document. The original Standard can be  obtained  online
238       at http://www.opengroup.org/unix/online.html .
239
240       Any  typographical  or  formatting  errors that appear in this page are
241       most likely to have been introduced during the conversion of the source
242       files  to  man page format. To report such errors, see https://www.ker
243       nel.org/doc/man-pages/reporting_bugs.html .
244
245
246
247IEEE/The Open Group                  2017                           GETMSG(3P)
Impressum