Go to the previous, next section.

msgrcv and msgsnd

SYNOPSIS

int msgsnd(int msqid, struct msgbuf *msgp, int msgsz, int msgflg);

int msgrcv(int msqid, struct msgbuf *msgp, int msgsz, long msgtyp, int msgflg);

PARAMETERS

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.

DESCRIPTION

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:

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:

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:

RETURN VALUE

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:

for msgrcv:

Go to the previous, next section.