Blame man-pages-posix-2013-a/man3p/getmsg.3p

Packit 7cfc04
'\" et
Packit 7cfc04
.TH GETMSG "3P" 2013 "IEEE/The Open Group" "POSIX Programmer's Manual"
Packit 7cfc04
.SH PROLOG
Packit 7cfc04
This manual page is part of the POSIX Programmer's Manual.
Packit 7cfc04
The Linux implementation of this interface may differ (consult
Packit 7cfc04
the corresponding Linux manual page for details of Linux behavior),
Packit 7cfc04
or the interface may not be implemented on Linux.
Packit 7cfc04
Packit 7cfc04
.SH NAME
Packit 7cfc04
getmsg,
Packit 7cfc04
getpmsg
Packit 7cfc04
\(em receive next message from a STREAMS file (\fBSTREAMS\fP)
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.LP
Packit 7cfc04
.nf
Packit 7cfc04
#include <stropts.h>
Packit 7cfc04
.P
Packit 7cfc04
int getmsg(int \fIfildes\fP, struct strbuf *restrict \fIctlptr\fP,
Packit 7cfc04
    struct strbuf *restrict \fIdataptr\fP, int *restrict \fIflagsp\fP);
Packit 7cfc04
int getpmsg(int \fIfildes\fP, struct strbuf *restrict \fIctlptr\fP,
Packit 7cfc04
    struct strbuf *restrict \fIdataptr\fP, int *restrict \fIbandp\fP,
Packit 7cfc04
    int *restrict \fIflagsp\fP);
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
function shall retrieve the contents of a message located at the head
Packit 7cfc04
of the STREAM head read queue associated with a STREAMS file and place
Packit 7cfc04
the contents into one or more buffers. The message contains either a
Packit 7cfc04
data part, a control part, or both. The data and control parts of the
Packit 7cfc04
message shall be placed into separate buffers, as described below. The
Packit 7cfc04
semantics of each part are defined by the originator of the message.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
function shall be equivalent to
Packit 7cfc04
\fIgetmsg\fR(),
Packit 7cfc04
except that it provides finer control over the priority of the messages
Packit 7cfc04
received. Except where noted, all requirements on
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
also pertain to
Packit 7cfc04
\fIgetpmsg\fR().
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR fildes
Packit 7cfc04
argument specifies a file descriptor referencing a STREAMS-based file.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
and
Packit 7cfc04
.IR dataptr
Packit 7cfc04
arguments each point to a
Packit 7cfc04
.BR strbuf
Packit 7cfc04
structure, in which the
Packit 7cfc04
.IR buf
Packit 7cfc04
member points to a buffer in which the data or control information is
Packit 7cfc04
to be placed, and the
Packit 7cfc04
.IR maxlen
Packit 7cfc04
member indicates the maximum number of bytes this buffer can hold. On
Packit 7cfc04
return, the
Packit 7cfc04
.IR len
Packit 7cfc04
member shall contain the number of bytes of data or control information
Packit 7cfc04
actually received. The
Packit 7cfc04
.IR len
Packit 7cfc04
member shall be set to 0 if there is a zero-length control or data part
Packit 7cfc04
and
Packit 7cfc04
.IR len
Packit 7cfc04
shall be set to \(mi1 if no data or control information is present in
Packit 7cfc04
the message.
Packit 7cfc04
.P
Packit 7cfc04
When
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
is called,
Packit 7cfc04
.IR flagsp
Packit 7cfc04
should point to an integer that indicates the type of message the
Packit 7cfc04
process is able to receive. This is described further below.
Packit 7cfc04
.P
Packit 7cfc04
The
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
argument is used to hold the control part of the message, and
Packit 7cfc04
.IR dataptr
Packit 7cfc04
is used to hold the data part of the message. If
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
(or
Packit 7cfc04
.IR dataptr )
Packit 7cfc04
is a null pointer or the
Packit 7cfc04
.IR maxlen
Packit 7cfc04
member is \(mi1, the control (or data) part of the message shall not be
Packit 7cfc04
processed and shall be left on the STREAM head read queue, and if the
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
(or
Packit 7cfc04
.IR dataptr )
Packit 7cfc04
is not a null pointer,
Packit 7cfc04
.IR len
Packit 7cfc04
shall be set to \(mi1. If the
Packit 7cfc04
.IR maxlen
Packit 7cfc04
member is set to 0 and there is a zero-length control (or data) part,
Packit 7cfc04
that zero-length part shall be removed from the read queue and
Packit 7cfc04
.IR len
Packit 7cfc04
shall be set to 0. If the
Packit 7cfc04
.IR maxlen
Packit 7cfc04
member is set to 0 and there are more than 0 bytes of control (or data)
Packit 7cfc04
information, that information shall be left on the read queue and
Packit 7cfc04
.IR len
Packit 7cfc04
shall be set to 0. If the
Packit 7cfc04
.IR maxlen
Packit 7cfc04
member in
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
(or
Packit 7cfc04
.IR dataptr )
Packit 7cfc04
is less than the control (or data) part of the message,
Packit 7cfc04
.IR maxlen
Packit 7cfc04
bytes shall be retrieved. In this case, the remainder of the message
Packit 7cfc04
shall be left on the STREAM head read queue and a non-zero return value
Packit 7cfc04
shall be provided.
Packit 7cfc04
.P
Packit 7cfc04
By default,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
shall process the first available message on the STREAM head read
Packit 7cfc04
queue. However, a process may choose to retrieve only high-priority
Packit 7cfc04
messages by setting the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
to RS_HIPRI. In this case,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
shall only process the next message if it is a high-priority message.
Packit 7cfc04
When the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
is 0, any available message shall be retrieved. In this case, on
Packit 7cfc04
return, the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
shall be set to RS_HIPRI if a high-priority message was retrieved, or 0
Packit 7cfc04
otherwise.
Packit 7cfc04
.P
Packit 7cfc04
For
Packit 7cfc04
\fIgetpmsg\fR(),
Packit 7cfc04
the flags are different. The
Packit 7cfc04
.IR flagsp
Packit 7cfc04
argument points to a bitmask with the following mutually-exclusive
Packit 7cfc04
flags defined: MSG_HIPRI, MSG_BAND, and MSG_ANY.
Packit 7cfc04
Like
Packit 7cfc04
\fIgetmsg\fR(),
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall process the first available message on the STREAM head read
Packit 7cfc04
queue. A process may choose to retrieve only high-priority messages by
Packit 7cfc04
setting the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
to MSG_HIPRI and the integer pointed to by
Packit 7cfc04
.IR bandp
Packit 7cfc04
to 0. In this case,
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall only process the next message if it is a high-priority message.
Packit 7cfc04
In a similar manner, a process may choose to retrieve a message from a
Packit 7cfc04
particular priority band by setting the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
to MSG_BAND and the integer pointed to by
Packit 7cfc04
.IR bandp
Packit 7cfc04
to the priority band of interest. In this case,
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall only process the next message if it is in a priority band equal
Packit 7cfc04
to, or greater than, the integer pointed to by
Packit 7cfc04
.IR bandp ,
Packit 7cfc04
or if it is a high-priority message. If a process wants to get the
Packit 7cfc04
first message off the queue, the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
should be set to MSG_ANY and the integer pointed to by
Packit 7cfc04
.IR bandp
Packit 7cfc04
should be set to 0. On return, if the message retrieved was a
Packit 7cfc04
high-priority message, the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
shall be set to MSG_HIPRI and the integer pointed to by
Packit 7cfc04
.IR bandp
Packit 7cfc04
shall be set to 0. Otherwise, the integer pointed to by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
shall be set to MSG_BAND and the integer pointed to by
Packit 7cfc04
.IR bandp
Packit 7cfc04
shall be set to the priority band of the message.
Packit 7cfc04
.P
Packit 7cfc04
If O_NONBLOCK is not set,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall block until a message of the type specified by
Packit 7cfc04
.IR flagsp
Packit 7cfc04
is available at the front of the STREAM head read queue. If O_NONBLOCK
Packit 7cfc04
is set and a message of the specified type is not present at the front
Packit 7cfc04
of the read queue,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall fail and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to
Packit 7cfc04
.BR [EAGAIN] .
Packit 7cfc04
.P
Packit 7cfc04
If a hangup occurs on the STREAM from which messages are retrieved,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall continue to operate normally, as described above, until the
Packit 7cfc04
STREAM head read queue is empty. Thereafter, they shall return 0 in the
Packit 7cfc04
.IR len
Packit 7cfc04
members of
Packit 7cfc04
.IR ctlptr
Packit 7cfc04
and
Packit 7cfc04
.IR dataptr .
Packit 7cfc04
.SH "RETURN VALUE"
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall return a non-negative value. A value of 0 indicates that a full
Packit 7cfc04
message was read successfully. A return value of MORECTL indicates
Packit 7cfc04
that more control
Packit 7cfc04
information is waiting for retrieval. A return value of MOREDATA
Packit 7cfc04
indicates that more data is waiting for retrieval. A return value of
Packit 7cfc04
the bitwise-logical OR of MORECTL and MOREDATA indicates that both
Packit 7cfc04
types of information remain. Subsequent
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
calls shall retrieve the remainder of the message. However, if a message
Packit 7cfc04
of higher priority has come in on the STREAM head read queue, the next
Packit 7cfc04
call to
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall retrieve that higher-priority message before retrieving the
Packit 7cfc04
remainder of the previous message.
Packit 7cfc04
.P
Packit 7cfc04
If the high priority control part of the message is consumed, the
Packit 7cfc04
message shall be placed back on the queue as a normal message of band
Packit 7cfc04
0. Subsequent
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
calls shall retrieve the remainder of the message. If, however, a
Packit 7cfc04
priority message arrives or already exists on the STREAM head, the
Packit 7cfc04
subsequent call to
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall retrieve the higher-priority message before retrieving the
Packit 7cfc04
remainder of the message that was put back.
Packit 7cfc04
.P
Packit 7cfc04
Upon failure,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall return \(mi1 and set
Packit 7cfc04
.IR errno
Packit 7cfc04
to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
The
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
functions shall fail if:
Packit 7cfc04
.TP
Packit 7cfc04
.BR EAGAIN
Packit 7cfc04
The O_NONBLOCK flag is set and no messages are available.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EBADF
Packit 7cfc04
The
Packit 7cfc04
.IR fildes
Packit 7cfc04
argument is not a valid file descriptor open for reading.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EBADMSG
Packit 7cfc04
The queued message to be read is not valid for
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
or a pending file descriptor is at the STREAM head.
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINTR
Packit 7cfc04
A signal was caught during
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIgetpmsg\fR().
Packit 7cfc04
.TP
Packit 7cfc04
.BR EINVAL
Packit 7cfc04
An illegal value was specified by
Packit 7cfc04
.IR flagsp ,
Packit 7cfc04
or the STREAM or multiplexer referenced by
Packit 7cfc04
.IR fildes
Packit 7cfc04
is linked (directly or indirectly) downstream from a multiplexer.
Packit 7cfc04
.TP
Packit 7cfc04
.BR ENOSTR
Packit 7cfc04
A STREAM is not associated with
Packit 7cfc04
.IR fildes .
Packit 7cfc04
.P
Packit 7cfc04
In addition,
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
shall fail if the STREAM head had processed an asynchronous error
Packit 7cfc04
before the call. In this case, the value of
Packit 7cfc04
.IR errno
Packit 7cfc04
does not reflect the result of
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
or
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
but reflects the prior error.
Packit 7cfc04
.LP
Packit 7cfc04
.IR "The following sections are informative."
Packit 7cfc04
.SH EXAMPLES
Packit 7cfc04
.SS "Getting Any Message"
Packit 7cfc04
.P
Packit 7cfc04
In the following example, the value of
Packit 7cfc04
.IR fd
Packit 7cfc04
is assumed to refer to an open STREAMS file. The call to
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
retrieves any available message on the associated STREAM-head read
Packit 7cfc04
queue, returning control and data information to the buffers pointed to
Packit 7cfc04
by
Packit 7cfc04
.IR ctrlbuf
Packit 7cfc04
and
Packit 7cfc04
.IR databuf ,
Packit 7cfc04
respectively.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stropts.h>
Packit 7cfc04
\&...
Packit 7cfc04
int fd;
Packit 7cfc04
char ctrlbuf[128];
Packit 7cfc04
char databuf[512];
Packit 7cfc04
struct strbuf ctrl;
Packit 7cfc04
struct strbuf data;
Packit 7cfc04
int flags = 0;
Packit 7cfc04
int ret;
Packit 7cfc04
.P
Packit 7cfc04
ctrl.buf = ctrlbuf;
Packit 7cfc04
ctrl.maxlen = sizeof(ctrlbuf);
Packit 7cfc04
.P
Packit 7cfc04
data.buf = databuf;
Packit 7cfc04
data.maxlen = sizeof(databuf);
Packit 7cfc04
.P
Packit 7cfc04
ret = getmsg (fd, &ctrl, &data, &flags);
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SS "Getting the First Message off the Queue"
Packit 7cfc04
.P
Packit 7cfc04
In the following example, the call to
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
retrieves the first available message on the associated STREAM-head
Packit 7cfc04
read queue.
Packit 7cfc04
.sp
Packit 7cfc04
.RS 4
Packit 7cfc04
.nf
Packit 7cfc04
\fB
Packit 7cfc04
#include <stropts.h>
Packit 7cfc04
\&...
Packit 7cfc04
.P
Packit 7cfc04
int fd;
Packit 7cfc04
char ctrlbuf[128];
Packit 7cfc04
char databuf[512];
Packit 7cfc04
struct strbuf ctrl;
Packit 7cfc04
struct strbuf data;
Packit 7cfc04
int band = 0;
Packit 7cfc04
int flags = MSG_ANY;
Packit 7cfc04
int ret;
Packit 7cfc04
.P
Packit 7cfc04
ctrl.buf = ctrlbuf;
Packit 7cfc04
ctrl.maxlen = sizeof(ctrlbuf);
Packit 7cfc04
.P
Packit 7cfc04
data.buf = databuf;
Packit 7cfc04
data.maxlen = sizeof(databuf);
Packit 7cfc04
.P
Packit 7cfc04
ret = getpmsg (fd, &ctrl, &data, &band, &flags);
Packit 7cfc04
.fi \fR
Packit 7cfc04
.P
Packit 7cfc04
.RE
Packit 7cfc04
.SH "APPLICATION USAGE"
Packit 7cfc04
None.
Packit 7cfc04
.SH RATIONALE
Packit 7cfc04
None.
Packit 7cfc04
.SH "FUTURE DIRECTIONS"
Packit 7cfc04
The
Packit 7cfc04
\fIgetmsg\fR()
Packit 7cfc04
and
Packit 7cfc04
\fIgetpmsg\fR()
Packit 7cfc04
functions may be removed in a future version.
Packit 7cfc04
.SH "SEE ALSO"
Packit 7cfc04
.IR "Section 2.6" ", " "STREAMS",
Packit 7cfc04
.IR "\fIpoll\fR\^(\|)",
Packit 7cfc04
.IR "\fIputmsg\fR\^(\|)",
Packit 7cfc04
.IR "\fIread\fR\^(\|)",
Packit 7cfc04
.IR "\fIwrite\fR\^(\|)"
Packit 7cfc04
.P
Packit 7cfc04
The Base Definitions volume of POSIX.1\(hy2008,
Packit 7cfc04
.IR "\fB<stropts.h>\fP"
Packit 7cfc04
.SH COPYRIGHT
Packit 7cfc04
Portions of this text are reprinted and reproduced in electronic form
Packit 7cfc04
from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
Packit 7cfc04
-- Portable Operating System Interface (POSIX), The Open Group Base
Packit 7cfc04
Specifications Issue 7, Copyright (C) 2013 by the Institute of
Packit 7cfc04
Electrical and Electronics Engineers, Inc and The Open Group.
Packit 7cfc04
(This is POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
Packit 7cfc04
event of any discrepancy between this version and the original IEEE and
Packit 7cfc04
The Open Group Standard, the original IEEE and The Open Group Standard
Packit 7cfc04
is the referee document. The original Standard can be obtained online at
Packit 7cfc04
http://www.unix.org/online.html .
Packit 7cfc04
Packit 7cfc04
Any typographical or formatting errors that appear
Packit 7cfc04
in this page are most likely
Packit 7cfc04
to have been introduced during the conversion of the source files to
Packit 7cfc04
man page format. To report such errors, see
Packit 7cfc04
https://www.kernel.org/doc/man-pages/reporting_bugs.html .