Results 1 to 4 of 4
Hello,
I am trying to implement posix message queue application. I am faced with an error on the mq_receive section. It says "Message too long". I've tried couple of small ...
- 09-10-2009 #1Just Joined!
- Join Date
- Sep 2009
- Posts
- 2
POSIX mq_receive issue: Message too long
Hello,
I am trying to implement posix message queue application. I am faced with an error on the mq_receive section. It says "Message too long". I've tried couple of small tweeks, but to no result. Please do suggest any rectificaitons.
mq_send section-works successfully
mq_receive section: error-Message too longCode:#include <mqueue.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #include <sys/stat.h> #include <string.h> #include <signal.h> #define MSG_SIZE 16 #define MQ_NAME "/msgqueue" int main(void) { mqd_t mqPXId; char *msg = "test"; if ((mqPXId = mq_open (MQ_NAME, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR, NULL)) ==-1) { printf ("sendTask: mq_open failed: %s\n", strerror(errno)); return 0; } if (mq_send (mqPXId, msg, MSG_SIZE, NULL) == -1) { printf ("sendTask: mq_send failed\n"); return 0; } else { printf ("sendTask: mq_send succeeded, msg sent: %s\n",msg); } return 0; }
Code:#include <stdio.h> #include <mqueue.h> #include <pthread.h> #include <string.h> #include <stdlib.h> #include <sys/stat.h> #include <errno.h> #define MSG_SIZE 16 #define MQ_NAME "/msgqueue" int main(void) { mqd_t mqPXId; /* msg queue descriptor */ char *msg; /* msg buffer */ // unsigned int prio; /* priority of message */ /* open message queue using default attributes */ if ((mqPXId = mq_open (MQ_NAME, O_RDWR , S_IWUSR | S_IRUSR, NULL)) == -1) { printf ("receiveTask: mq_open failed\n"); return 0; } /* try reading from queue */ if (mq_receive (mqPXId,(char *)&msg,MSG_SIZE, NULL) == -1) { printf ("receiveTask: mq_receive failed: %s\n",strerror(errno)); return 0; } else { printf ("receiveTask: Msg of priority received:\n\t\t%s\n", msg); } return 0; }
- 09-11-2009 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Look at this part of the sender code:
Note that you send MSG_SIZE bytes, yet the string is only 5 bytes long (4 chars + NUL). On the send, you MUST specify the number of bytes in the message, 5 in this case.Code:if (mq_send (mqPXId, msg, MSG_SIZE, NULL) == -1) { printf ("sendTask: mq_send failed\n"); return 0; }Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-04-2010 #3Just Joined!
- Join Date
- Dec 2007
- Posts
- 1
Was this ever resolved. I took the suggestions above but I still receive the "Message too long" for mq_receive().
See code below:
#include <stdio.h>
#include <mqueue.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#define MSG_SIZE 16
#define MQ_NAME "/msgqueue"
int main(void) {
mqd_t mqPXId; /* msg queue descriptor */
char buffer[MSG_SIZE];
ssize_t bytes_received;
/* open message queue using default attributes */
if ((mqPXId = mq_open (MQ_NAME, O_RDWR , S_IWUSR | S_IRUSR, NULL)) == -1) {
printf ("receiveTask: mq_open failed\n");
return 0;
}
/* try reading from queue */
if (mq_receive (mqPXId, buffer, sizeof(buffer), NULL) == -1) {
printf ("receiveTask: mq_receive failed: %s\n",strerror(errno));
return 0;
}
else {
printf ("receiveTask: Msg of priority received:\n\t\t%s\n", buffer);
}
return 0;
}
- 02-04-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
So, show us the code where you send the message.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote