The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unable to extract a tag from a very long XML message Sapna_Sai UNIX for Dummies Questions & Answers 3 05-13-2009 11:28 AM
How to limit max no of message in a posix message queue mohit3884 High Level Programming 0 06-10-2008 06:03 AM
POSIX message queue size Vourhey Linux 7 06-09-2008 03:42 AM
posix ipc message queue cadanir HP-UX 6 05-01-2006 08:59 PM
POSIX Message Queue - Settings Deepa High Level Programming 0 02-07-2003 10:13 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-10-2009
katwalatapan katwalatapan is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 1
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

Code:

#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;
}

mq_receive section: error-Message too long


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;
        }

Bits Awarded / Charged to katwalatapan for this Post
Date User Comment Amount
09-10-2009 vgersh99 thanks for using the code tag on the FIRST post! 3,000
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0