PROLOG |NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLES |APPLICATION USAGE |RATIONALE |FUTURE DIRECTIONS |SEE ALSO |COPYRIGHT | |
PUTMSG(3P) POSIX Programmer's ManualPUTMSG(3P)This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
putmsg, putpmsg — send a message on a STREAM (STREAMS)
#include <stropts.h> int putmsg(intfildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, intflags); int putpmsg(intfildes, const struct strbuf *ctlptr, const struct strbuf *dataptr, intband, intflags);
Theputmsg() function shall create a message from a process buffer(s) and send the message to a STREAMS file. The message may contain either a data part, a control part, or both. The data and control parts are distinguished by placement in separate buffers, as described below. The semantics of each part are defined by the STREAMS module that receives the message. Theputpmsg() function is equivalent toputmsg(), except that the process can send messages in different priority bands. Except where noted, all requirements onputmsg() also pertain toputpmsg(). Thefildes argument specifies a file descriptor referencing an open STREAM. Thectlptr anddataptr arguments each point to astrbufstructure. Thectlptr argument points to the structure describing the control part, if any, to be included in the message. Thebuf member in thestrbufstructure points to the buffer where the control information resides, and thelen member indicates the number of bytes to be sent. Themaxlen member is not used byputmsg(). In a similar manner, the argumentdataptr specifies the data, if any, to be included in the message. Theflags argument indicates what type of message should be sent and is described further below. To send the data part of a message, the application shall ensure thatdataptr is not a null pointer and thelen member ofdataptr is 0 or greater. To send the control part of a message, the application shall ensure that the corresponding values are set forctlptr. No data (control) part shall be sent if eitherdataptr(ctlptr) is a null pointer or thelen member ofdataptr(ctlptr) is set to -1. Forputmsg(), if a control part is specified andflags is set to RS_HIPRI, a high priority message shall be sent. If no control part is specified, andflags is set to RS_HIPRI,putmsg() shall fail and seterrno to[EINVAL]. Ifflags is set to 0, a normal message (priority band equal to 0) shall be sent. If a control part and data part are not specified andflags is set to 0, no message shall be sent and 0 shall be returned. Forputpmsg(), the flags are different. Theflags argument is a bitmask with the following mutually-exclusive flags defined: MSG_HIPRI and MSG_BAND. Ifflags is set to 0,putpmsg() shall fail and seterrno to[EINVAL]. If a control part is specified andflags is set to MSG_HIPRI andband is set to 0, a high-priority message shall be sent. Ifflags is set to MSG_HIPRI and either no control part is specified orband is set to a non-zero value,putpmsg() shall fail and seterrno to[EINVAL]. Ifflags is set to MSG_BAND, then a message shall be sent in the priority band specified byband. If a control part and data part are not specified andflags is set to MSG_BAND, no message shall be sent and 0 shall be returned. Theputmsg() function shall block if the STREAM write queue is full due to internal flow control conditions, with the following exceptions: * For high-priority messages,putmsg() shall not block on this condition and continues processing the message. * For other messages,putmsg() shall not block but shall fail when the write queue is full and O_NONBLOCK is set. Theputmsg() function shall also block, unless prevented by lack of internal resources, while waiting for the availability of message blocks in the STREAM, regardless of priority or whether O_NONBLOCK has been specified. No partial message shall be sent.
Upon successful completion,putmsg() andputpmsg() shall return 0; otherwise, they shall return -1 and seterrno to indicate the error.
Theputmsg() andputpmsg() functions shall fail if:EAGAINA non-priority message was specified, the O_NONBLOCK flag is set, and the STREAM write queue is full due to internal flow control conditions; or buffers could not be allocated for the message that was to be created.EBADFfildes is not a valid file descriptor open for writing.EINTRA signal was caught duringputmsg().EINVALAn undefined value is specified inflags, orflags is set to RS_HIPRI or MSG_HIPRI and no control part is supplied, or the STREAM or multiplexer referenced byfildes is linked (directly or indirectly) downstream from a multiplexer, orflags is set to MSG_HIPRI andband is non-zero (forputpmsg() only).ENOSRBuffers could not be allocated for the message that was to be created due to insufficient STREAMS memory resources.ENOSTRA STREAM is not associated withfildes.ENXIOA hangup condition was generated downstream for the specified STREAM.EPIPEorEIO Thefildes argument refers to a STREAMS-based pipe and the other end of the pipe is closed. A SIGPIPE signal is generated for the calling thread.ERANGEThe size of the data part of the message does not fall within the range specified by the maximum and minimum packet sizes of the topmost STREAM module. This value is also returned if the control part of the message is larger than the maximum configured size of the control part of a message, or if the data part of a message is larger than the maximum configured size of the data part of a message. In addition,putmsg() andputpmsg() shall fail if the STREAM head had processed an asynchronous error before the call. In this case, the value oferrno does not reflect the result ofputmsg() orputpmsg(), but reflects the prior error.The following sections are informative.
Sending a High-Priority Message The value offd is assumed to refer to an open STREAMS file. This call toputmsg() does the following: 1. Creates a high-priority message with a control part and a data part, using the buffers pointed to byctrlbuf anddatabuf, respectively. 2. Sends the message to the STREAMS file identified byfd. #include <stropts.h> #include <string.h> ... int fd; char *ctrlbuf = "This is the control part"; char *databuf = "This is the data part"; struct strbuf ctrl; struct strbuf data; int ret; ctrl.buf = ctrlbuf; ctrl.len = strlen(ctrlbuf); data.buf = databuf; data.len = strlen(databuf); ret = putmsg(fd, &ctrl, &data, MSG_HIPRI);Using putpmsg() This example has the same effect as the previous example. In this example, however, theputpmsg() function creates and sends the message to the STREAMS file. #include <stropts.h> #include <string.h> ... int fd; char *ctrlbuf = "This is the control part"; char *databuf = "This is the data part"; struct strbuf ctrl; struct strbuf data; int ret; ctrl.buf = ctrlbuf; ctrl.len = strlen(ctrlbuf); data.buf = databuf; data.len = strlen(databuf); ret = putpmsg(fd, &ctrl, &data, 0, MSG_HIPRI);
None.
None.
Theputmsg() andputpmsg() functions may be removed in a future version.
Section 2.6,STREAMS,getmsg(3p),poll(3p),read(3p),write(3p) The Base Definitions volume of POSIX.1‐2017,stropts.h(0p)
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online athttp://www.opengroup.org/unix/online.html . Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html .IEEE/The Open Group 2017PUTMSG(3P)Pages that refer to this page:stropts.h(0p), getmsg(3p), ioctl(3p), poll(3p)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |