I am trying the following code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <mqueue.h>
#include "sctp.h"
#include "s1ap.h"
#include "messages.h"
void send_to_s1ap(void);
int main()
{
pthread_t tid;
pthread_create(&tid, NULL, s1ap, (void *)&tid);
pthread_create(&tid, NULL, sctp, (void *)&tid);
send_to_s1ap();
pthread_exit(NULL);
return 0;
}
void send_to_s1ap(void)
{
int status = 0;
mqd_t mqfd;
struct mq_attr attr;
int open_flags = 0;
int priority_of_msg;
message msg;
attr.mq_maxmsg = 100;
attr.mq_msgsize = 100;
attr.mq_flags = 0;
open_flags = O_WRONLY|O_CREAT;
mqfd = mq_open("/s1ap_queue",open_flags,0660,&attr);
if (mqfd == -1)
{
printf("mq_open failure from main\n");
return;
}
/* Fill in a test message buffer to send */
msg.msg_id = 1;
msg.data[0] = 'P';
msg.data[1] = 'R';
msg.data[2] = 'I';
msg.data[3] = 'O';
msg.data[4] = 'R';
msg.data[5] = 'I';
msg.data[6] = 'T';
msg.data[7] = 'Y';
msg.data[8] = '1';
msg.data[9] = 'a';
priority_of_msg = 1;
status = mq_send(mqfd,(const char *) &msg,sizeof(msg),priority_of_msg);
if (status == -1)
{
perror("mq_send failure on mqfd\n");
}
else
{
printf("successful call to mq_send\n");
}
if (mq_close(mqfd) == -1)
{
printf("mq_close failure on mqfd");
}
}
where in messages.h I declare
#define max_msg_size 10
typedef struct message {
int msg_id;
char data[max_msg_size];
message;
I get the following error code: mq_send failure on mqfd : Message too long
I have commented out all the code in the client side (which is doing mq_receive) , so the error doesnt come from there. Any ideas what is causing the problem?
I tried changing
attr.mq_maxmsg = 100; attr.mq_msgsize = 100;
but it didnt help
Edit:
I did an example with
void send_to_s1ap(void)
{
int status = 0;
mqd_t mqfd;
struct mq_attr attr;
int open_flags = 0;
int priority_of_msg;
char buffer2[12] = "Hello world";
attr.mq_maxmsg = 10;
attr.mq_msgsize = 100;
attr.mq_flags = 0;
attr.mq_curmsgs = 0;
open_flags = O_WRONLY|O_CREAT;
mqfd = mq_open("/s1ap_queue",open_flags,0660,&attr);
if (mqfd == -1)
{
printf("mq_open failure from main\n");
return;
}
/* Fill in a test message buffer to send */
priority_of_msg = 1;
status = mq_send(mqfd,buffer2,sizeof(buffer2),priority_of_msg);
if (status == -1)
{
perror("mq_send failure on mqfd\n");
}
else
{
printf("successful call to mq_send\n");
}
if (mq_close(mqfd) == -1)
{
printf("mq_close failure on mqfd");
}
}
and its still failing with
mq_send failure on mqfd : Message too long
So I guess its not the struct that is causing the issue, but indeed for some reason its not sending big structs/strings. Any idea why?