I am getting bad address as the error code (14) when i execute below program.
int main (int argc, char *argv[])
{
char response [20];
struct mq_attr buf;
buf.mq_msgsize = sizeof (response);
buf.mq_maxmsg = 5;
response[0]= '1';
mqd_t handle = mq_open ("/test", O_CREAT | O_RDWR, 0, &buf);
int status = mq_timedsend (handle, (char *) &response, sizeof (response), 0,250000);
printf("value of status - %d\n", errno);
pthread_t my_thread_id;
pthread_attr_t attr;
}
Additional information: Updated the code as below and now i get error code 90 (message too long)
#include <stdio.h>
#include <errno.h>
#include <mqueue.h>
#include <pthread.h>
#include <time.h>
static struct timespec RcvCmdWaitTime;
int main (int argc, char *argv[])
{
char response [10];
struct mq_attr buf;
RcvCmdWaitTime.tv_sec = 0;
RcvCmdWaitTime.tv_nsec = 250000;
mqd_t handle;
buf.mq_msgsize = sizeof response;
buf.mq_maxmsg = 1;
int status;
if((handle = mq_open ("/test", O_CREAT | O_RDWR , S_IRWXU | S_IRWXG, &buf))==-1)
printf("mq-open error, error no:%d\n",errno);
status = mq_timedsend (handle, &response[0], sizeof response , 0, &RcvCmdWaitTime);
if (status == -1)
printf("mq_timedsend: Error:%d\n",errno);
}
i use : gcc -pthread multi_thr.c -lrt to compile
You should only test
errno
if the previous call indicated an error.In this case if
mq_timedsend()
had returned-1
.Also note that
response
isn't nescessaysizeof
is an operator not a functionAlso you want to check the outcome of
mq_open()
: