Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @brief POSIX Message Queues
0007  * 
0008  * This file contains the definitions related to POSIX Message Queues.
0009  * 
0010  * The structure of the routines is identical to that of POSIX
0011  * Message_queues to leave the option of having unnamed message
0012  * queues at a future date.  They are currently not part of the
0013  * POSIX standard but unnamed message_queues are.  This is also
0014  * the reason for the apparently unnecessary tracking of
0015  * the process_shared attribute.  [In addition to the fact that
0016  * it would be trivial to add pshared to the mq_attr structure
0017  * and have process private message queues.]
0018  *
0019  * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
0020  * time.
0021  */
0022 
0023 /*
0024  *  COPYRIGHT (c) 1989-2011.
0025  *  On-Line Applications Research Corporation (OAR).
0026  *
0027  * Redistribution and use in source and binary forms, with or without
0028  * modification, are permitted provided that the following conditions
0029  * are met:
0030  * 1. Redistributions of source code must retain the above copyright
0031  *    notice, this list of conditions and the following disclaimer.
0032  * 2. Redistributions in binary form must reproduce the above copyright
0033  *    notice, this list of conditions and the following disclaimer in the
0034  *    documentation and/or other materials provided with the distribution.
0035  *
0036  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0037  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0038  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0039  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0040  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0041  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0042  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0043  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0044  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0045  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0046  * POSSIBILITY OF SUCH DAMAGE.
0047  */
0048 
0049 #ifndef _MQUEUE_H
0050 #define _MQUEUE_H
0051 
0052 
0053 #include <unistd.h>
0054 
0055 #if defined(_POSIX_MESSAGE_PASSING)
0056 
0057 #include <sys/types.h>
0058 
0059 /**
0060  * @defgroup POSIX_MQUEUE POSIX Message Queues
0061  *
0062  * @ingroup POSIXAPI
0063  * 
0064  */
0065 /**@{**/
0066 
0067 #ifdef __cplusplus
0068 extern "C" {
0069 #endif
0070 
0071 /*
0072  *  15.1.1 Data Structures, P1003.1b-1993, p. 271
0073  */
0074 
0075 /**
0076  * Message queue id type.
0077  *
0078  * NOTE: Use uint32_t since all POSIX Ids are 32-bit currently.
0079  */
0080 typedef uint32_t  mqd_t;
0081 
0082 /**
0083  * This is the message queue attributes structure.
0084  */
0085 struct mq_attr {
0086   /** This is the message queue flags */
0087   long  mq_flags;
0088   /** This is the maximum number of messages */
0089   long  mq_maxmsg;
0090   /** This is the maximum message size */
0091   long  mq_msgsize;
0092   /** This is the mumber of messages currently queued */
0093   long  mq_curmsgs;
0094 };
0095 
0096 /**
0097  * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
0098  */
0099 mqd_t mq_open(
0100   const char *name,
0101   int         oflag,
0102   ...
0103 );
0104 
0105 /**
0106  * 15.2.2 Close a Message Queue, P1003.1b-1993, p. 275
0107  */
0108 int mq_close(
0109   mqd_t  mqdes
0110 );
0111 
0112 /**
0113  * @brief Remove a message queue.
0114  *
0115  * 15.2.2 Remove a Message Queue, P1003.1b-1993, p. 276
0116  *
0117  * NOTE:  The structure of the routines is identical to that of POSIX
0118  *        Message_queues to leave the option of having unnamed message
0119  *        queues at a future date.  They are currently not part of the
0120  *        POSIX standard but unnamed message_queues are.  This is also
0121  *        the reason for the apparently unnecessary tracking of
0122  *        the process_shared attribute.  [In addition to the fact that
0123  *        it would be trivial to add pshared to the mq_attr structure
0124  *        and have process private message queues.]
0125  *
0126  *        This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open
0127  *        time.
0128  */
0129 int mq_unlink(
0130   const char *name
0131 );
0132 
0133 /**
0134  * 15.2.4 Send a Message to a Message Queue, P1003.1b-1993, p. 277
0135  *
0136  * NOTE; P1003.4b/D8, p. 45 adds mq_timedsend().
0137  */
0138 int mq_send(
0139   mqd_t         mqdes,
0140   const char   *msg_ptr,
0141   size_t        msg_len,
0142   unsigned int  msg_prio
0143 );
0144 
0145 #if defined(_POSIX_TIMEOUTS)
0146 
0147 #include <time.h>
0148 
0149 /**
0150  * @brief Send a message to a message queue.
0151  * 
0152  * @see mq_send()
0153  */
0154 int mq_timedsend(
0155   mqd_t                  mqdes,
0156   const char            *msg_ptr,
0157   size_t                 msg_len,
0158   unsigned int           msg_prio,
0159   const struct timespec *abstime
0160 );
0161 
0162 #endif /* _POSIX_TIMEOUTS */
0163 
0164 /**
0165  * @brief Receive a message from a message queue. 
0166  * 
0167  * 15.2.5 Receive a Message From a Message Queue, P1003.1b-1993, p. 279
0168  *
0169  * NOTE: P1003.4b/D8, p. 45 adds mq_timedreceive().
0170  */
0171 ssize_t mq_receive(
0172   mqd_t         mqdes,
0173   char         *msg_ptr,
0174   size_t        msg_len,
0175   unsigned int *msg_prio
0176 );
0177 
0178 #if defined(_POSIX_TIMEOUTS)
0179 
0180 ssize_t mq_timedreceive(
0181   mqd_t                  mqdes,
0182   char                  *__restrict msg_ptr,
0183   size_t                 msg_len,
0184   unsigned int          *__restrict msg_prio,
0185   const struct timespec *__restrict abstime
0186 );
0187 
0188 #endif /* _POSIX_TIMEOUTS */
0189 
0190 #if defined(_POSIX_REALTIME_SIGNALS)
0191 
0192 /**
0193  * @brief Notify process that a message is available on a queue.
0194  *
0195  * 15.2.6 Notify Process that a Message is Available on a Queue,
0196  *        P1003.1b-1993, p. 280
0197  */
0198 int mq_notify(
0199   mqd_t                  mqdes,
0200   const struct sigevent *notification
0201 );
0202 
0203 #endif /* _POSIX_REALTIME_SIGNALS */
0204 
0205 /**
0206  * @brief Set message queue attributes.
0207  *
0208  * 15.2.7 Set Message Queue Attributes, P1003.1b-1993, p. 281
0209  */
0210 int mq_setattr(
0211   mqd_t                 mqdes,
0212   const struct mq_attr *__restrict mqstat,
0213   struct mq_attr       *__restrict omqstat
0214 );
0215 
0216 /*
0217  *  15.2.8 Get Message Queue Attributes, P1003.1b-1993, p. 283
0218  */
0219 
0220 int mq_getattr(
0221   mqd_t           mqdes,
0222   struct mq_attr *mqstat
0223 );
0224 
0225 /** @} */
0226 
0227 #ifdef __cplusplus
0228 }
0229 #endif
0230 
0231 #endif /* _POSIX_MESSAGE_PASSING */
0232 
0233 #endif
0234 /* end of include file */