| | |
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 * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi





