--- a/src/PosixMQ.h Thu Dec 15 21:43:59 2022 +0100
+++ b/src/PosixMQ.h Wed Feb 22 20:45:57 2023 +0100
@@ -27,6 +27,7 @@
class PosixMQ {
private:
+ const static size_t MSG_COUNT = 10; // TODO: configurable/dynamic
const static size_t MSG_SIZE = 8192; // TODO: configurable/dynamic
std::string queueName;
mqd_t handle = -2;
@@ -43,7 +44,11 @@
}
static PosixMQ* open(std::string queueName, bool unlinkOnClose = false) {
- mqd_t handle = mq_open(queueName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ struct mq_attr attr = (struct mq_attr){0};
+ attr.mq_maxmsg = MSG_COUNT;
+ attr.mq_msgsize = MSG_SIZE;
+
+ mqd_t handle = mq_open(queueName.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, &attr);
if (handle >= 0) return new PosixMQ(queueName, handle, unlinkOnClose);
else throw std::logic_error("Unable to open PosixMQ: " + queueName + " error: " + strerror(errno));
}