MSGOP(S) XENIX System V MSGOP(S)
Name
msgop - Message operations.
Syntax
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
int msgsnd (msqid, msgp, msgsz, msgflg)
int msquid;
struct msgbuf *msgp;
int msgsz, msgflg;
int msgrcv (msqid, msgp, msgsz, msgtyp, msgflg)
int msqid;
struct msgbuf *msgp;
int msgsz;
long msgtyp;
int msgflg;
Description
msgsnd is used to send a message to the queue associated
with the message queue identifier specified by msqid.
msgp points to the structure containing the message. The
structure contains the following members:
long mtype; /* message type */
char mtext[]; /* message text */
mtype is a positive integer that can be used by the
receiving process for message selection (see msgrcv below).
mtext is text of length msgsz bytes. msgsz can range from 0
to a maximum imposed by the system.
msgflg specifies the action to be taken if one or more of
the following conditions is true:
The number of bytes already on the queue is equal to
msg_qbytes (see intro(S)).
The number of messages on all the queues system-wide
equals the system-imposed limit.
The actions msgflg specifies include:
The message will not be sent and the calling process
will return immediately if (msgflg & IPC_NOWAIT ) is
true.
If (msgflg & IPC_NOWAIT ) is false, the calling process
will suspend execution until one of following the
Page 1 (printed 8/7/87)
MSGOP(S) XENIX System V MSGOP(S)
occurs:
The condition causing the suspension no longer
exists. In this case, the message is sent.
msqid is removed from the system (see msgctl(S)).
In this case, errno is set equal to EIDRM, and a
value of -1 is returned.
The calling process receives a signal that is to
be caught. In this case the message is not sent
and the calling process resumes execution in the
manner described in signal(S).
msgsnd will fail and no message will be sent if one or more
of the following are true:
msqid is not a valid message queue identifier.
[EINVAL]
Operation permission is denied to the calling process
(see intro(S)). [EACCES]
mtype is less than 1. [EINVAL]
The message cannot be sent for one of the preceding
reasons and (msgflg & IPC_NOWAIT ) is true. [EAGAIN]
msgsz is less than zero or greater than the system-
imposed limit. [EINVAL]
msgp points to an illegal address. [EFAULT]
Upon successful completion, the following actions are taken
with respect to the data structure associated with msqid
(see Intro(S)).
msg_qnum is incremented by 1.
msg_lspid is set equal to the process ID of the calling
process.
msg_stime is set equal to the current time.
Page 2 (printed 8/7/87)
MSGOP(S) XENIX System V MSGOP(S)
msgrcv reads a message from the queue associated with the
message queue identifier (msqid) and places it in the
structure pointed to by msgp. The structure contains the
following members:
long mtype; /* message type */
char mtext[]; /* message text */
mtype is the received message's type. This is specified by
the sending process. mtext is the text of the message.
msgsz gives the size in bytes of mtext. If the received
message is larger than msgsz bytes and (msgflg &
MSG_NOERROR) is true, the message is truncated to msgsz
bytes. The truncated part of the message is lost and no
notice of the truncation is given to the calling process.
msgtyp specifies the type of message requested:
If msgtype equals zero, the first message on the queue
is received.
If msgtyp is greater than zero, the first message of
type msgtyp is received.
If msgtyp is less than zero, the first message of the
lowest type less than or equal to the absolute value of
msgtyp is received.
msgflg specifies an action if a message of the desired type
is not on the queue. These include:
If (msgflg & IPC_NOWAIT) is true, calling process
returns immediately with a return value of -1 and errno
is set equal to ENOMSG.
If (msgflg & IPC_NOWAIT) is false, calling process
suspends execution until one of the following occurs:
A message of the desired type is placed on the
queue.
msqid is removed from the system. errno is set
equal to EIDRM and a value of -1 is returned.
The calling process receives a signal that is to
be caught. In this case, a message is not
received and the calling process resumes execution
in the manner described in signal(S).
msgrcv will fail and no message will be received if one or
more of the following are true:
Page 3 (printed 8/7/87)
MSGOP(S) XENIX System V MSGOP(S)
msqid is not a valid message queue identifier.
[EINVAL]
buf points to an address in read-only shared data.
[EINVAL]
Operation permission is denied to the calling process.
[EACCES]
msgsz is less than 0. [EINVAL]
mtext is greater than msgsz and (msgflg & MSG_NOERROR )
is false. [E2BIG]
The queue does not contain a message of the desired
type and (msgtyp & IPC_NOWAIT ) is true. [ENOMSG]
msgp points to an illegal address. [EFAULT]
Upon successful completion, the following actions are taken
on the data structure associated with msqid (see Intro(S)).
msg_qnum is decreased by 1.
msg_lrpid is set equal to the process ID of the calling
process.
msg_rtime is set equal to the current time.
Return Values
If msgsnd or msgrcv return because of a signal received, a
value of -1 is returned to the calling process and errno is
set to EINTR. If these operations return because msqid was
removed from the system, a value of -1 is returned and errno
is set to EIDRM.
Upon successful completion, the return values are:
msgsnd returns 0.
msgrcv returns a value equal to the number of bytes
placed into mtext.
Otherwise, -1 is returned and errno is set to indicate the
error.
See Also
intro(S), msgctl(S), msgget(S), signal(S).
Notes
Programs using this function must be compiled with the -Me
compiler option.
Page 4 (printed 8/7/87)