PUTMSG(3)                  POSIX Programmer's Manual                 PUTMSG(3)



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

NNAAMMEE
       putmsg, putpmsg -- send a message on a STREAM (SSTTRREEAAMMSS)

SSYYNNOOPPSSIISS
       #include <stropts.h>

       int putmsg(int _f_i_l_d_e_s, const struct strbuf *_c_t_l_p_t_r,
           const struct strbuf *_d_a_t_a_p_t_r, int _f_l_a_g_s);
       int putpmsg(int _f_i_l_d_e_s, const struct strbuf *_c_t_l_p_t_r,
           const struct strbuf *_d_a_t_a_p_t_r, int _b_a_n_d, int _f_l_a_g_s);

DDEESSCCRRIIPPTTIIOONN
       The _p_u_t_m_s_g() 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.

       The _p_u_t_p_m_s_g() function is equivalent to _p_u_t_m_s_g(), except that the
       process can send messages in different priority bands.  Except where
       noted, all requirements on _p_u_t_m_s_g() also pertain to _p_u_t_p_m_s_g().

       The _f_i_l_d_e_s argument specifies a file descriptor referencing an open
       STREAM. The _c_t_l_p_t_r and _d_a_t_a_p_t_r arguments each point to a ssttrrbbuuff
       structure.

       The _c_t_l_p_t_r argument points to the structure describing the control
       part, if any, to be included in the message. The _b_u_f member in the
       ssttrrbbuuff structure points to the buffer where the control information
       resides, and the _l_e_n member indicates the number of bytes to be sent.
       The _m_a_x_l_e_n member is not used by _p_u_t_m_s_g().  In a similar manner, the
       argument _d_a_t_a_p_t_r specifies the data, if any, to be included in the
       message. The _f_l_a_g_s 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 that
       _d_a_t_a_p_t_r is not a null pointer and the _l_e_n member of _d_a_t_a_p_t_r is 0 or
       greater. To send the control part of a message, the application shall
       ensure that the corresponding values are set for _c_t_l_p_t_r.  No data
       (control) part shall be sent if either _d_a_t_a_p_t_r(_c_t_l_p_t_r) is a null
       pointer or the _l_e_n member of _d_a_t_a_p_t_r(_c_t_l_p_t_r) is set to -1.

       For _p_u_t_m_s_g(), if a control part is specified and _f_l_a_g_s is set to
       RS_HIPRI, a high priority message shall be sent. If no control part is
       specified, and _f_l_a_g_s is set to RS_HIPRI, _p_u_t_m_s_g() shall fail and set
       _e_r_r_n_o to [[EEIINNVVAALL]].  If _f_l_a_g_s 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 and _f_l_a_g_s is set to 0, no message shall be sent and 0
       shall be returned.

       For _p_u_t_p_m_s_g(), the flags are different. The _f_l_a_g_s argument is a bitmask
       with the following mutually-exclusive flags defined: MSG_HIPRI and
       MSG_BAND. If _f_l_a_g_s is set to 0, _p_u_t_p_m_s_g() shall fail and set _e_r_r_n_o to
       [[EEIINNVVAALL]].  If a control part is specified and _f_l_a_g_s is set to MSG_HIPRI
       and _b_a_n_d is set to 0, a high-priority message shall be sent. If _f_l_a_g_s
       is set to MSG_HIPRI and either no control part is specified or _b_a_n_d is
       set to a non-zero value, _p_u_t_p_m_s_g() shall fail and set _e_r_r_n_o to
       [[EEIINNVVAALL]].  If _f_l_a_g_s is set to MSG_BAND, then a message shall be sent in
       the priority band specified by _b_a_n_d.  If a control part and data part
       are not specified and _f_l_a_g_s is set to MSG_BAND, no message shall be
       sent and 0 shall be returned.

       The _p_u_t_m_s_g() function shall block if the STREAM write queue is full due
       to internal flow control conditions, with the following exceptions:

        *  For high-priority messages, _p_u_t_m_s_g() shall not block on this
           condition and continues processing the message.

        *  For other messages, _p_u_t_m_s_g() shall not block but shall fail when
           the write queue is full and O_NONBLOCK is set.

       The _p_u_t_m_s_g() 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.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _p_u_t_m_s_g() and _p_u_t_p_m_s_g() shall return 0;
       otherwise, they shall return -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _p_u_t_m_s_g() and _p_u_t_p_m_s_g() functions shall fail if:

       EEAAGGAAIINN A 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.

       EEBBAADDFF  _f_i_l_d_e_s is not a valid file descriptor open for writing.

       EEIINNTTRR  A signal was caught during _p_u_t_m_s_g().

       EEIINNVVAALL An undefined value is specified in _f_l_a_g_s, or _f_l_a_g_s is set to
              RS_HIPRI or MSG_HIPRI and no control part is supplied, or the
              STREAM or multiplexer referenced by _f_i_l_d_e_s is linked (directly
              or indirectly) downstream from a multiplexer, or _f_l_a_g_s is set to
              MSG_HIPRI and _b_a_n_d is non-zero (for _p_u_t_p_m_s_g() only).

       EENNOOSSRR  Buffers could not be allocated for the message that was to be
              created due to insufficient STREAMS memory resources.

       EENNOOSSTTRR A STREAM is not associated with _f_i_l_d_e_s.

       EENNXXIIOO  A hangup condition was generated downstream for the specified
              STREAM.

       EEPPIIPPEE or EEIIOO
              The _f_i_l_d_e_s 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.

       EERRAANNGGEE The 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, _p_u_t_m_s_g() and _p_u_t_p_m_s_g() shall fail if the STREAM head had
       processed an asynchronous error before the call. In this case, the
       value of _e_r_r_n_o does not reflect the result of _p_u_t_m_s_g() or _p_u_t_p_m_s_g(),
       but reflects the prior error.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
   SSeennddiinngg aa HHiigghh--PPrriioorriittyy MMeessssaaggee
       The value of _f_d is assumed to refer to an open STREAMS file. This call
       to _p_u_t_m_s_g() does the following:

        1. Creates a high-priority message with a control part and a data
           part, using the buffers pointed to by _c_t_r_l_b_u_f and _d_a_t_a_b_u_f,
           respectively.

        2. Sends the message to the STREAMS file identified by _f_d.


           #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);

   UUssiinngg ppuuttppmmssgg(())
       This example has the same effect as the previous example. In this
       example, however, the _p_u_t_p_m_s_g() 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);

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       The _p_u_t_m_s_g() and _p_u_t_p_m_s_g() functions may be removed in a future
       version.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._6, _S_T_R_E_A_M_S, _g_e_t_m_s_g(), _p_o_l_l(), _r_e_a_d(), _w_r_i_t_e()

       The Base Definitions volume of POSIX.1-2017, <<ssttrrooppttss..hh>>

CCOOPPYYRRIIGGHHTT
       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 at http://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, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                            PUTMSG(3)
