[ Previous |
Next |
Contents |
Glossary |
Home |
Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1
msgsnd Subroutine
Purpose
Sends a message.
Library
Standard C Library (libc.a)
Syntax
#include <sys/msg.h>
int msgsnd (MessageQueueID, MessagePointer,MessageSize, MessageFlag)
int MessageQueueID, MessageFlag;
const void *MessagePointer;
size_t MessageSize;
Description
The msgsnd subroutine sends a message to the queue specified by the
MessageQueueID parameter. The current process must have write permission to perform this operation. The
MessagePointer parameter points to an msgbuf structure containing the message. The sys/msg.h file
defines the msgbuf structure. The structure contains the following fields:
mtyp_t mtype; /* Message type */
char mtext[1]; /* Beginning of message text */
The mtype field specifies a positive integer used by the
receiving process for message selection. The mtext field can be any text of the length in bytes
specified by the MessageSize parameter. The MessageSize parameter can range from 0 to the maximum limit
imposed by the system.
The following example shows a typical user-defined msgbuf structure that includes
sufficient space for the largest message:
struct my_msgbuf
mtyp_t mtype;
char mtext[MSGSIZ]; /* MSGSIZ is the
size of the largest message */
Note:
The routine may coredump instead of returning EFAULT
when an invalid pointer is passed in case of 64-bit application
calling 32-bit kernel interface.
The following system limits apply to the message queue:
- Maximum message size is 65,535 bytes for releases prior to AIX 4.1.5 and is 4 Megabytes for release 4.1.5 and later releases.
- Maximum number of messages per queue is 8192.
- Maximum number of message queue IDs is 4096 for AIX
releases before 4.3.2 and 131072 for AIX 4.3.2 and following.
- Maximum number of bytes in a queue is
4 65,535 bytes for releases prior to AIX 4.1.5 is 4 Megabytes for
release 4.1.5 and later releases.
Note: For a 64-bit process, the mtype field is 64 bits long. However, for compatibility with 32-bit processes, the most significant 32 bits must be 0 and will not be put on the message queue. For a 64-bit receiver process, the mtype will again be extended to 64 bits with the most significant bits 0.
The MessageFlag parameter specifies the action to be taken if the message cannot
be sent for one of the following reasons:
- The number of bytes already on the queue is equal to the number of bytes defined by the
msg_qbytes structure.
- The total number of messages on the queue is equal to a system-imposed limit.
These actions are as follows:
- If the MessageFlag parameter is set to the IPC_NOWAIT value, the message is
not sent, and the msgsnd subroutine returns a value of -1 and sets the errno global variable to the
EAGAIN error code.
- If the MessageFlag parameter is set to 0, the calling process suspends execution until
one of the following occurs:
- The condition responsible for the suspension no longer exists, in which case the message is
sent.
- The MessageQueueID parameter is removed from the system. (For information on how to
remove the MessageQueueID parameter, see the msgctl subroutine.) When this
occurs, the errno global variable is set equal to the EIDRM error code, 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 prescribed in the sigaction subroutine.
Parameters
MessageQueueID |
Specifies the queue to which the message is sent. |
MessagePointer |
Points to a msgbuf structure containing the message. |
MessageSize |
Specifies the length, in bytes, of the message text. |
MessageFlag |
Specifies the action to be taken if the message cannot be sent. |
Return Values
Upon successful completion, a value of 0 is returned and the following actions are
taken with respect to the data structure associated with the MessageQueueID parameter:
- The msg_qnum field is incremented by 1.
- The msg_lspid field is set equal to the process ID of the calling process.
- The msg_stime field is set equal to the current time.
If the msgsnd subroutine is unsuccessful, a value of -1 is returned and the
errno global variable is set to indicate the error.
Error Codes
The msgsnd subroutine is unsuccessful and no message is sent if one or more
of the following conditions is true:
EINVAL |
The MessageQueueID parameter is not a valid message queue identifier. |
EACCES |
The calling process is denied permission for the specified operation. |
EINVAL |
The mtype field is less than 1. |
EAGAIN |
The message cannot be sent for one of the reasons stated previously, and the MessageFlag parameter is
set to the IPC_NOWAIT value. |
EINVAL |
The MessageSize parameter is less than 0 or greater than the system-imposed limit. |
EFAULT |
The MessagePointer parameter points outside of the address space of the process. |
EINTR |
The msgsnd subroutine received a signal. |
EIDRM |
The message queue identifier specified by the MessageQueueID parameter has been removed from the
system. |
ENOMEM |
The message could not be sent because not enough storage space was available. |
EINVAL |
The upper 32-bits of the 64-bit mtype field for a 64-bit process is not 0. |
Implementation Specifics
This subroutine is part of Base Operating System (BOS) Runtime.
Related Information
The msgctl subroutine, msgget subroutine, msgrcv subroutine, msgxrcv subroutine, sigaction subroutine.
[ Previous |
Next |
Contents |
Glossary |
Home |
Search ]