1PUTMSG(3P) POSIX Programmer's Manual PUTMSG(3P)
2
3
4
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
12 putmsg, putpmsg - send a message on a STREAM (STREAMS)
13
15 #include <stropts.h>
16
17 int putmsg(int fildes, const struct strbuf *ctlptr,
18 const struct strbuf *dataptr, int flags);
19 int putpmsg(int fildes, const struct strbuf *ctlptr,
20 const struct strbuf *dataptr, int band, int flags);
21
22
24 The putmsg() function shall create a message from a process buffer(s)
25 and send the message to a STREAMS file. The message may contain either
26 a data part, a control part, or both. The data and control parts are
27 distinguished by placement in separate buffers, as described below. The
28 semantics of each part are defined by the STREAMS module that receives
29 the message.
30
31 The putpmsg() function is equivalent to putmsg(), except that the
32 process can send messages in different priority bands. Except where
33 noted, all requirements on putmsg() also pertain to putpmsg().
34
35 The fildes argument specifies a file descriptor referencing an open
36 STREAM. The ctlptr and dataptr arguments each point to a strbuf struc‐
37 ture.
38
39 The ctlptr argument points to the structure describing the control
40 part, if any, to be included in the message. The buf member in the str‐
41 buf structure points to the buffer where the control information
42 resides, and the len member indicates the number of bytes to be sent.
43 The maxlen member is not used by putmsg(). In a similar manner, the
44 argument dataptr specifies the data, if any, to be included in the mes‐
45 sage. The flags argument indicates what type of message should be sent
46 and is described further below.
47
48 To send the data part of a message, the application shall ensure that
49 dataptr is not a null pointer and the len member of dataptr is 0 or
50 greater. To send the control part of a message, the application shall
51 ensure that the corresponding values are set for ctlptr. No data (con‐
52 trol) part shall be sent if either dataptr( ctlptr) is a null pointer
53 or the len member of dataptr( ctlptr) is set to -1.
54
55 For putmsg(), if a control part is specified and flags is set to
56 RS_HIPRI, a high priority message shall be sent. If no control part is
57 specified, and flags is set to RS_HIPRI, putmsg() shall fail and set
58 errno to [EINVAL]. If flags is set to 0, a normal message (priority
59 band equal to 0) shall be sent. If a control part and data part are not
60 specified and flags is set to 0, no message shall be sent and 0 shall
61 be returned.
62
63 For putpmsg(), the flags are different. The flags argument is a bitmask
64 with the following mutually-exclusive flags defined: MSG_HIPRI and
65 MSG_BAND. If flags is set to 0, putpmsg() shall fail and set errno to
66 [EINVAL]. If a control part is specified and flags is set to MSG_HIPRI
67 and band is set to 0, a high-priority message shall be sent. If flags
68 is set to MSG_HIPRI and either no control part is specified or band is
69 set to a non-zero value, putpmsg() shall fail and set errno to [EIN‐
70 VAL]. If flags is set to MSG_BAND, then a message shall be sent in the
71 priority band specified by band. If a control part and data part are
72 not specified and flags is set to MSG_BAND, no message shall be sent
73 and 0 shall be returned.
74
75 The putmsg() function shall block if the STREAM write queue is full due
76 to internal flow control conditions, with the following exceptions:
77
78 * For high-priority messages, putmsg() shall not block on this condi‐
79 tion and continues processing the message.
80
81 * For other messages, putmsg() shall not block but shall fail when the
82 write queue is full and O_NONBLOCK is set.
83
84 The putmsg() function shall also block, unless prevented by lack of
85 internal resources, while waiting for the availability of message
86 blocks in the STREAM, regardless of priority or whether O_NONBLOCK has
87 been specified. No partial message shall be sent.
88
90 Upon successful completion, putmsg() and putpmsg() shall return 0; oth‐
91 erwise, they shall return -1 and set errno to indicate the error.
92
94 The putmsg() and putpmsg() functions shall fail if:
95
96 EAGAIN A non-priority message was specified, the O_NONBLOCK flag is
97 set, and the STREAM write queue is full due to internal flow
98 control conditions; or buffers could not be allocated for the
99 message that was to be created.
100
101 EBADF fildes is not a valid file descriptor open for writing.
102
103 EINTR A signal was caught during putmsg().
104
105 EINVAL An undefined value is specified in flags, or flags is set to
106 RS_HIPRI or MSG_HIPRI and no control part is supplied, or the
107 STREAM or multiplexer referenced by fildes is linked (directly
108 or indirectly) downstream from a multiplexer, or flags is set to
109 MSG_HIPRI and band is non-zero (for putpmsg() only).
110
111 ENOSR Buffers could not be allocated for the message that was to be
112 created due to insufficient STREAMS memory resources.
113
114 ENOSTR A STREAM is not associated with fildes.
115
116 ENXIO A hangup condition was generated downstream for the specified
117 STREAM.
118
119 EPIPE or EIO
120 The fildes argument refers to a STREAMS-based pipe and the other
121 end of the pipe is closed. A SIGPIPE signal is generated for the
122 calling thread.
123
124 ERANGE The size of the data part of the message does not fall within
125 the range specified by the maximum and minimum packet sizes of
126 the topmost STREAM module. This value is also returned if the
127 control part of the message is larger than the maximum config‐
128 ured size of the control part of a message, or if the data part
129 of a message is larger than the maximum configured size of the
130 data part of a message.
131
132
133 In addition, putmsg() and putpmsg() shall fail if the STREAM head had
134 processed an asynchronous error before the call. In this case, the
135 value of errno does not reflect the result of putmsg() or putpmsg(),
136 but reflects the prior error.
137
138 The following sections are informative.
139
141 Sending a High-Priority Message
142 The value of fd is assumed to refer to an open STREAMS file. This call
143 to putmsg() does the following:
144
145 1. Creates a high-priority message with a control part and a data
146 part, using the buffers pointed to by ctrlbuf and databuf, respec‐
147 tively.
148
149 2. Sends the message to the STREAMS file identified by fd.
150
151 #include <stropts.h>
152 #include <string.h>
153 ...
154 int fd;
155 char *ctrlbuf = "This is the control part";
156 char *databuf = "This is the data part";
157 struct strbuf ctrl;
158 struct strbuf data;
159 int ret;
160
161
162 ctrl.buf = ctrlbuf;
163 ctrl.len = strlen(ctrlbuf);
164
165
166 data.buf = databuf;
167 data.len = strlen(databuf);
168
169
170 ret = putmsg(fd, &ctrl, &data, MSG_HIPRI);
171
172 Using putpmsg()
173 This example has the same effect as the previous example. In this exam‐
174 ple, however, the putpmsg() function creates and sends the message to
175 the STREAMS file.
176
177
178 #include <stropts.h>
179 #include <string.h>
180 ...
181 int fd;
182 char *ctrlbuf = "This is the control part";
183 char *databuf = "This is the data part";
184 struct strbuf ctrl;
185 struct strbuf data;
186 int ret;
187
188
189 ctrl.buf = ctrlbuf;
190 ctrl.len = strlen(ctrlbuf);
191
192
193 data.buf = databuf;
194 data.len = strlen(databuf);
195
196
197 ret = putpmsg(fd, &ctrl, &data, 0, MSG_HIPRI);
198
200 None.
201
203 None.
204
206 None.
207
209 STREAMS, getmsg(), poll(), read(), write(), the Base Definitions volume
210 of IEEE Std 1003.1-2001, <stropts.h>
211
213 Portions of this text are reprinted and reproduced in electronic form
214 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
215 -- Portable Operating System Interface (POSIX), The Open Group Base
216 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
217 Electrical and Electronics Engineers, Inc and The Open Group. In the
218 event of any discrepancy between this version and the original IEEE and
219 The Open Group Standard, the original IEEE and The Open Group Standard
220 is the referee document. The original Standard can be obtained online
221 at http://www.opengroup.org/unix/online.html .
222
223
224
225IEEE/The Open Group 2003 PUTMSG(3P)