Go to the previous, next section.
int msgsnd(int msqid, struct msgbuf *msgp, int msgsz,
int msgflg);
int msgrcv(int msqid, struct msgbuf *msgp, int msgsz,
long msgtyp, int msgflg);
msqid: [in] the message queue.
msgp: for msgsnd, [in] points to the message to send. For msgrcv, [out] points to the buffer where to put the message.
msgsz: [in] size of the mtext part of the buffer. The
maximum possible size is MSGMAX and is currently 4080 bytes.
msgflg: [in] flags (see description).
msgtyp: [in] the type of message to receive.
msgp must point to a buffer having the following structure:
struct msgbuf {
long mtype; /* message type, must > 0 */
char mtext[1]; /* message data */
}
The calling process must have read permission on the queue to call
msgrcv and write permission on the queue to call msgsnd.
msgsnd tries to enqueue the message. If msglfg is set to
IPC_NOWAIT and the queue is full, the call fails. Otherwise the
call blocks. If the send succeed, the message queue structure is updated
as follow:
msg_lspid is set to the pid of the calling process.
msg_qnum is incremented by 1.
msg_stime is set to the current time.
msgrcv dequeues a message from the message queue. If the message
to be dequeued has a length greater than msgsz, then the call
fails. If the length is greater but the MSG_NOERROR flag is
specified, the message gets truncated (and the truncated information is
lost forever). The message to be dequeued can be choosed by the
following values of msgtyp:
MSG_EXCEPT is
not specified, the first message of type msgtyp on the queue will
be dequeued, otherwise the first message not of type msgtyp
on the queue will be dequeued.
If the flag IPC_NOWAIT is specified and there is no message of
the specified type on the message queue, the call will fail, otherwise
the call will block. On success, the queue data structure is updated as
follow:
msg_lrpid is set to the pid of the calling process.
msg_qnum is decremented by 1.
msg_rtime is set to the current time.
On success msgsnd returns zero and msgrcv returns the
number of bytes copied in the mtext array. On error -1 is
returned and errno is set to one of the following values:
for msgsnd:
EAGAIN: IPC_NOWAIT was specified and the queue is
full.
EACCESS: the calling task does not have write permission on
the queue.
EIDRM: the queue has been removed.
EINVAL: invalid msqid, msgsz or mtype value.
EFAULT, EINTR and ENOMEM.
for msgrcv:
E2BIG: MSG_NOERROR is not specified and the message
that should be dequeued is too bigger than msgsz.
EACCESS: the calling task does not have read permission on
the queue.
EIDRM: the queue has been removed.
EINVAL: invalid msqid or msgsz value.
ENOMSG: IPC_NOWAIT was specified no message of the
specified type is on the queue.
EFAULT, EINTR
Go to the previous, next section.