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