1.\" $NetBSD: msgrcv.2,v 1.1 1995/10/16 23:49:20 jtc Exp $ 2.\" 3.\" Copyright (c) 1995 Frank van der Linden 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. All advertising materials mentioning features or use of this software 15.\" must display the following acknowledgement: 16.\" This product includes software developed for the NetBSD Project 17.\" by Frank van der Linden 18.\" 4. The name of the author may not be used to endorse or promote products 19.\" derived from this software without specific prior written permission 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31.\"/ 32.Dd August 17, 1995 33.Dt MSGRCV 2 34.Os NetBSD 35.Sh NAME 36.Nm msgrcv 37.Nd receive a message from a message queue 38.Sh SYNOPSIS 39.Fd #include <sys/types.h> 40.Fd #include <sys/ipc.h> 41.Fd #include <sys/msg.h> 42.Ft int 43.Fn msgrcv "int msqid" "void *msgp" "size_t msgsz" "long msgtyp" "int msgflg" 44.Sh DESCRIPTION 45The 46.Fn msgrcv 47function receives a message from the message queue specified in 48.Fa msqid , 49and places it into the structure pointed to by 50.Fa msgp . 51This structure should consist of the following members: 52.Bd -literal 53 long mtype; /* message type */ 54 char mtext[1]; /* body of message */ 55.Ed 56 57.Va mtype 58is an integer greater than 0 that can be used for selecting messages, 59.Va mtext 60is an array of bytes, with a size up to that of the system limit (MSGMAX). 61 62The value of 63.Fa msgtyp 64has one of the following meanings: 65.Bl -bullet 66.It 67.Fa msgtyp 68is greater than 0. The first message of type 69.Fa msgtyp 70will be received. 71.It 72.Fa msgtyp 73is equal to 0. The first message on the queue will be received. 74.It 75.Fa msgtyp 76is less than 0. The first message of the lowest message type that is 77less than or equal to the absolute value of 78.Fa msgtyp 79will be received. 80.El 81 82.Fa msgsz 83specifies the maximum length of the requested message. If the received 84message has a length greater than 85.Fa msgsz 86it will be silently truncated if the MSG_NOERROR flag is set in 87.Fa msgflg , 88otherwise an error will be returned. 89 90If no matching message is present on the message queue specified by 91.Fa msqid , 92the behaviour of 93.Fn msgrcv 94depends on whether the IPC_NOWAIT flag is set in 95.Fa msgflg 96or not. If IPC_NOWAIT is set, 97.Fn msgrcv 98will immediately return a value of -1, and set 99.Va errno 100to EAGAIN. If IPC_NOWAIT is not set, the calling process will be blocked 101until: 102.Bl -bullet 103.It 104A message of the requested type becomes available on the message queue. 105.It 106The message queue is removed, in which case -1 will be returned, and 107.Va errno 108set to EINVAL. 109.It 110A signal is received and caught. -1 is returned, and 111.Va errno 112set to EINTR. 113.El 114 115If a message is successfully received, the data structure associated with 116.Fa msqid 117is updated as follows: 118.Bl -bullet 119.It 120.Va msg_cbytes 121is decremented by the size of the message. 122.It 123.Va msg_lrpid 124is set to the pid of the caller. 125.It 126.Va msg_lrtime 127is set to the current time. 128.It 129.Va msg_qnum 130is decremented by 1. 131.Sh RETURN VALUES 132Upon successful completion, 133.Fn msgrcv 134returns the number of bytes received into the 135.Va mtext 136field of the structure pointed to by 137.Fa msgp . 138Otherwise, -1 is returned, and 139.Va errno 140set to indicate the error. 141.Sh ERRORS 142.Fn msgrcv 143will fail if: 144.Bl -tag -width Er 145.It Bq Er EINVAL 146.Fa msqid 147is not a valid message queue identifier 148 149The message queue was removed while 150.Fn msgrcv 151was waiting for a message of the requested type to become available on it. 152 153.Fa msgsz 154is less than 0. 155.It Bq Er E2BIG 156A matching message was received, but its size was greater than 157.Fa msgsz 158and the MSG_NOERROR flag was not set in 159.Fa msgflg . 160.It Bq Er EACCESS 161The calling process does not have read access to the message queue. 162.It Bq Er EFAULT 163.Fa msgp 164points to an invalid address. 165.It Bq Er EINTR 166The system call was interrupted by the delivery of a signal. 167.It Bq Er EAGAIN 168There is no message of the requested type available on the message queue, 169and IPC_NOWAIT is set in 170.Fa msgflg . 171.Sh SEE ALSO 172.Xr msgsnd 2 , 173.Xr msgctl 2 , 174.Xr msgget 2 175.Sh BUGS 176NetBSD does not define the EIDRM error value, which should be used in 177the case of a removed message queue, nor the ENOMSG value, which 178should be used when no suitable message is available and IPC_NOWAIT 179is set. 180.Sh HISTORY 181Message queues appeared in the first release of AT&T Unix System V. 182