I am getting the exception: file1.c: mq_send: Message too long
The error seems self explanatory but I can not figure it out.
I have the struct and files:
typedef struct {
char path[5011];
char sharedMemSegmentNameBuf[30];
} messageQueueStruct;
file1.c
#include <sys/mman.h>
#define MAX_CACHE_REQUEST_LEN 5041
messageQueueStruct mqStruct;
int maxPathLength = MAX_CACHE_REQUEST_LEN - sizeof(mqStruct.sharedMemSegmentNameBuf);
strncpy(mqStruct.path, path, maxPathLength);
strncpy(mqStruct.sharedMemSegmentNameBuf, sharedMemSegmentNameBuf, sizeof(mqStruct.sharedMemSegmentNameBuf));
if (mq_send(qdCache, (const char *) &mqStruct, sizeof(mqStruct), 0) == -1)
{
perror("handle_with_cache: mq_send");
exit(1);
}
file2.c
#include <sys/mman.h>
#define MAX_CACHE_REQUEST_LEN 5041
struct mq_attr attributes;
attributes.mq_maxmsg = MAX_MESSAGES;
attributes.mq_msgsize = MAX_CACHE_REQUEST_LEN;
messageQueueStruct receiveStruct;
int maxPathLength = MAX_CACHE_REQUEST_LEN - sizeof(receiveStruct.sharedMemSegmentNameBuf);
messageQueueStruct receiveStruct;
if (mq_receive(qdCache, (char *) &receiveStruct, MAX_CACHE_REQUEST_LEN, NULL) == -1)
{
perror("process request: mq_receive");
exit(1);
}
It looks to me that the sizes line up on the receive/ send sides. I also tested with just a char[] buffer and it worked. Some references I have looked at:
https://w3.cs.jmu.edu/kirkpams/OpenCSF/Books/cs361/html/MessPassMQ.html