default maxmsg + msgsize v_0 tip
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 22 Feb 2023 20:45:57 +0100
branchv_0
changeset 9 2f116bd15f27
parent 8 9f89ecc071bf
default maxmsg + msgsize
src/PosixMQ.h
--- 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));
 	}