| | |
POSIX message queue error in mq_receive()
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 0
Hello,
Could anyone please explain a reason why data could not be received from a POSIX message queue using mq_receive(), called from a different file. Following is my code for a test that i'm running to try and transfer data from one file to another.
main.c
recfun.h
recfun.c
Please do let me know if there could be any reason why I receive "Message too long" error from mq_receive, even when I have allocated sufficient memory.
Thank you.
Regards,
Tapan.
Could anyone please explain a reason why data could not be received from a POSIX message queue using mq_receive(), called from a different file. Following is my code for a test that i'm running to try and transfer data from one file to another.
main.c
c Syntax (Toggle Plain Text)
#include "recfun.h" int main() { datastruct *data; char *qname="/queue"; qdes=mq_open(qname, O_RDWR|O_CREAT|O_NONBLOCK, 0777, NULL); if(qdes==-1) { printf("Cannot open queue\n"); } data=(datastruct*)malloc(sizeof(datastruct)); data->i=3; data->c="3 is the data"; printf("data->i=%d\n", data->i); printf("data->c=%s\n", data->c); if(mq_send(qdes, (char *)data, 128, 0)==-1) { printf("Cannot send data onto the queue\n"); } recv_fun(qdes); free(data); mq_close(qdes); mq_unlink(qname); return (0); }
recfun.h
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <stdlib.h> #include <mqueue.h> #include <string.h> typedef struct { int i; char *c; }datastruct; static mqd_t qdes; void recv_fun(mqd_t qdes);
recfun.c
c Syntax (Toggle Plain Text)
#include "recfun.h" void recv_fun(mqd_t qdes) { datastruct *data1; data1=(datastruct *)malloc(sizeof(datastruct)); if(mq_receive(qdes, (char *)&data1, 128, 0)==-1) { printf("Cannot receive data from queue\n"); } printf("data1->i=%d\n", data1->i); printf("data1->c=%s\n", data1->c); free(data1); }
Please do let me know if there could be any reason why I receive "Message too long" error from mq_receive, even when I have allocated sufficient memory.
Thank you.
Regards,
Tapan.
![]() |
Other Threads in the C Forum
- Previous Thread: circular linked list
- Next Thread: C program for 2^i array
| Thread Tools | Search this Thread |
#include adobe ansi api array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic fflush file fork forloop framework frequency getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi





