Ejemplo n.º 1
0
        public MessageQueue(int length, string queueName)
        {
            int cbMessage = Marshal.SizeOf <T>();

            if (cbMessage > 8192)
            {
                throw new ArgumentOutOfRangeException("By default, Linux limits size of queue messages to 8kb");
            }
            if (length > 10)
            {
                throw new ArgumentOutOfRangeException("By default, Linux limits the queue to 10 pending messages");
            }

            int    pid  = Process.GetCurrentProcess().Id;
            string name = $"/{ queueName }.{ pid }";

            MessageQueueAttributes mqa = new MessageQueueAttributes()
            {
                flags       = eMessageQueueFlags.NonBlocking,
                maxMessages = length,
                messageSize = cbMessage
            };
            int fd = MQ.mq_open(name, queueFlags, eFileAccess.OwnerAllAccess, ref mqa);

            if (fd < 0)
            {
                throw LibC.exception("mq_open", fd);
            }

            handle    = fd;
            this.name = name;
        }
Ejemplo n.º 2
0
 public static extern int mq_open([In, MarshalAs(UnmanagedType.LPUTF8Str)] string name, eFileFlags flags, eFileAccess access, [In] ref MessageQueueAttributes attributes);