1998-02-16 18:28:37 +03:00
|
|
|
.\" $NetBSD: msgsnd.2,v 1.5 1998/02/16 15:28:37 kleink Exp $
|
1995-10-17 02:49:07 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1995 Frank van der Linden
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed for the NetBSD Project
|
|
|
|
.\" by Frank van der Linden
|
|
|
|
.\" 4. The name of the author may not be used to endorse or promote products
|
|
|
|
.\" derived from this software without specific prior written permission
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1997-11-27 13:24:44 +03:00
|
|
|
.\"
|
1995-10-17 02:49:07 +03:00
|
|
|
.Dd August 17, 1995
|
|
|
|
.Dt MSGSND 2
|
|
|
|
.Os NetBSD
|
|
|
|
.Sh NAME
|
|
|
|
.Nm msgsnd
|
|
|
|
.Nd send a message to a message queue
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Fd #include <sys/types.h>
|
|
|
|
.Fd #include <sys/ipc.h>
|
|
|
|
.Fd #include <sys/msg.h>
|
|
|
|
.Ft int
|
|
|
|
.Fn msgsnd "int msqid" "void *msgp" "size_t msgsz" "int msgflg"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn msgsnd
|
|
|
|
function sends a message from the message queue specified in
|
|
|
|
.Fa msqid .
|
|
|
|
.Fa msgp
|
1997-11-27 13:24:44 +03:00
|
|
|
points to a structure containing the message. This structure should
|
1995-10-17 02:49:07 +03:00
|
|
|
consist of the following members:
|
|
|
|
.Bd -literal
|
|
|
|
long mtype; /* message type */
|
|
|
|
char mtext[1]; /* body of message */
|
|
|
|
.Ed
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
.Va mtype
|
|
|
|
is an integer greater than 0 that can be used for selecting messages (see
|
1997-11-27 13:24:44 +03:00
|
|
|
.Xr msgrcv 2 ) .
|
1995-10-17 02:49:07 +03:00
|
|
|
.Va mtext
|
1997-11-27 13:24:44 +03:00
|
|
|
is an array of bytes, with size up to the system limit
|
|
|
|
.Dv MSGMAX .
|
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
If the number of bytes already on the message queue plus
|
|
|
|
.Fa msgsz
|
1997-11-27 13:24:44 +03:00
|
|
|
is greater than the maximum number of bytes in the message queue
|
|
|
|
.Pf ( Va msg_qbytes ,
|
1995-10-17 02:49:07 +03:00
|
|
|
see
|
|
|
|
.Xr msgctl 2 ) ,
|
1997-11-27 13:24:44 +03:00
|
|
|
or if the number of messages on all queues system-wide is already equal to
|
1995-10-17 02:49:07 +03:00
|
|
|
the system limit,
|
|
|
|
.Fa msgflg
|
|
|
|
determines the action of
|
|
|
|
.Fn msgsnd .
|
|
|
|
If
|
|
|
|
.Fa msgflg
|
1997-11-27 13:24:44 +03:00
|
|
|
has
|
|
|
|
.Dv IPC_NOWAIT
|
|
|
|
mask set in it, the call will return immediately. If
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa msgflg
|
1997-11-27 13:24:44 +03:00
|
|
|
does not have
|
|
|
|
.Dv IPC_NOWAIT
|
|
|
|
set in it, the call will block until:
|
1995-10-17 02:49:07 +03:00
|
|
|
.Bl -bullet
|
|
|
|
.It
|
1997-11-27 13:24:44 +03:00
|
|
|
The condition which caused the call to block no longer exists.
|
|
|
|
The message was sent.
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
1997-11-27 13:24:44 +03:00
|
|
|
The message queue is removed, in which case -1 will be returned and
|
1995-10-17 02:49:07 +03:00
|
|
|
.Va errno
|
1997-11-27 13:24:44 +03:00
|
|
|
set to
|
|
|
|
.Er EINVAL .
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
|
|
|
The caller catches a signal. The call returns with
|
|
|
|
.Va errno
|
1997-11-27 13:24:44 +03:00
|
|
|
set to
|
|
|
|
.Er EINTR .
|
1995-10-17 02:49:07 +03:00
|
|
|
.El
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
After a successful call, the data structure associated with the message
|
|
|
|
queue is updated in the following way:
|
|
|
|
.Bl -bullet
|
|
|
|
.It
|
|
|
|
.Va msg_cbytes
|
1997-11-27 13:24:44 +03:00
|
|
|
is incremented by
|
|
|
|
.Fa msgsz .
|
1995-10-17 02:49:07 +03:00
|
|
|
.It
|
|
|
|
.Va msg_qnum
|
|
|
|
is incremented by 1.
|
|
|
|
.It
|
|
|
|
.Va msg_lspid
|
|
|
|
is set to the pid of the calling process.
|
|
|
|
.It
|
|
|
|
.Va msg_stime
|
|
|
|
is set to the current time.
|
|
|
|
.El
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
Upon successful completion, 0 is returned. Otherwise, -1 is returned and
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.Sh ERRORS
|
|
|
|
.Fn msgsnd
|
|
|
|
will fail if:
|
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
.Fa msqid
|
1998-02-16 18:28:37 +03:00
|
|
|
is not a valid message queue identifier,
|
|
|
|
or the value of
|
|
|
|
.Fa mtype
|
|
|
|
is less than 1.
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
The message queue was removed while
|
|
|
|
.Fn msgsnd
|
|
|
|
was waiting for a resource to become available in order to deliver the
|
|
|
|
message.
|
1997-11-27 13:24:44 +03:00
|
|
|
.Pp
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa msgsz
|
|
|
|
is less than 0, or greater than
|
|
|
|
.Va msg_qbytes .
|
1997-11-27 10:36:24 +03:00
|
|
|
.It Bq Er EACCES
|
1995-10-17 02:49:07 +03:00
|
|
|
The calling process does not have write access to the message queue.
|
|
|
|
.It Bq Er EAGAIN
|
1997-11-27 13:24:44 +03:00
|
|
|
There was no space for this message either on the queue or in the whole
|
|
|
|
system, and
|
|
|
|
.Dv IPC_NOWAIT
|
|
|
|
was set in
|
1995-10-17 02:49:07 +03:00
|
|
|
.Fa msgflg .
|
|
|
|
.It Bq Er EFAULT
|
|
|
|
.Fa msgp
|
|
|
|
points to an invalid address.
|
|
|
|
.It Bq Er EINTR
|
|
|
|
The system call was interrupted by the delivery of a signal.
|
|
|
|
.El
|
1997-03-27 11:20:35 +03:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr msgctl 2 ,
|
|
|
|
.Xr msgget 2 ,
|
|
|
|
.Xr msgrcv 2
|
1995-10-17 02:49:07 +03:00
|
|
|
.Sh BUGS
|
1997-11-27 13:24:44 +03:00
|
|
|
.Nx
|
|
|
|
does not define the
|
|
|
|
.Er EIDRM
|
|
|
|
error value, which should be used
|
1995-10-17 02:49:07 +03:00
|
|
|
in the case of a removed message queue.
|
|
|
|
.Sh HISTORY
|
1997-11-27 13:24:44 +03:00
|
|
|
Message queues appeared in the first release of
|
|
|
|
.At V .
|