title: message queue send and receive
body: <p>I am having following program in vxworks which is part of big program</p>
  
  <pre><code> /* defines */
  #define MAX_MESSAGES 100
  #define MAX_MESSAGE_LENGTH 50
  
  
  if ((msgQStudyId = msgQCreate(MAX_MESSAGES,MAX_MESSAGE_LENGTH,MSG_Q_FIFO)) == NULL) {
          printf("msgQCreate in failed\n");
  }
  
  
  CVenkyMsgQWrite *pMsgWrite = new CVenkyMsgQWrite();
      pMsgWrite-&gt;OpenWrite();
  
  
      CVenkyMsgQRead *pMsgRead = new CVenkyMsgQRead();
      pMsgRead-&gt;OpenRead();
  
  class CVenkyMsgQWrite {
  
  public :
      // Constructors and destructors:
      CVenkyMsgQWrite();
      ~CVenkyMsgQWrite();
  
      RESULT OpenWrite(void);
      void TaskLoop(void);
  
  };
  
  
  class CVenkyMsgQRead {
  
  public :
      // Constructors and destructors:
      CVenkyMsgQRead();
      ~CVenkyMsgQRead();
  
      RESULT OpenRead(void);
      void TaskLoop(void);
  
  
  
  CVenkyMsgQWrite::CVenkyMsgQWrite() {
      // Open(void);
  }
  
  CVenkyMsgQWrite::~CVenkyMsgQWrite() { }
  
  static int WriteTask(const void *envPtr)
  {    
      CVenkyMsgQWrite *ctrl = (CVenkyMsgQWrite *)envPtr;
      try
      {
          ctrl-&gt;TaskLoop();   // Normal run
          return CI857_ERROR;
      }
      catch(...)
      {
          CI857DBG(printError,("Error in Controller input task\n",0,0,0,0,0,0));      
      }
      return CI857_ERROR;
  }
  
  RESULT CVenkyMsgQWrite::OpenWrite(void) {
  
      RESULT ret = CI857_OK;
  
      taskSpawn( "VenkyMsgQWrite", 
          78, 
          0,
          4096,  /* stack size */
          WriteTask, 
          this, 2,3,4,5,6,7,8,9,10);
      return ret;
  }
  
  void CVenkyMsgQWrite::TaskLoop(void)
  {
      STATUS MsgQStatus = OK;
  
      // MsgQStatus = msgQSend(msgQStudyId, (char*)pPHData, iDataLength, NO_WAIT, MSG_PRI_NORMAL );
      // if(ERROR == MsgQStatus)
      // {
          // m_pILogHandler-&gt;Log((cConfigMod|cError),"#%d: Error: SendToConfMsgQ() msgQSend failed with Err %d.",__LINE__,errnoGet());
      // }
  
      while(1) {
  
          char message[] = "message";
  
          /* send message */
          if((msgQSend(msgQStudyId,message,strlen(message), WAIT_FOREVER,     MSG_PRI_NORMAL)) == ERROR) {
              printf("msgQSend in CVenkyMsgQWrite::TaskLoop failed\n");
          }
          else {
              printf("msgQSend in CVenkyMsgQWrite::TaskLoop success\n");
          }
           vosSleepMs( 1000 );
      }
  
  
  
  }
  
  CVenkyMsgQRead::CVenkyMsgQRead() {
      // Open(void);
  }
  
  CVenkyMsgQRead::~CVenkyMsgQRead() { }
  
  static int ReadTask(const void *envPtr)
  {    
      CVenkyMsgQRead *ctrl = (CVenkyMsgQRead *)envPtr;
      try
      {
          ctrl-&gt;TaskLoop();   // Normal run
          return CI857_ERROR;
      }
      catch(...)
      {
          CI857DBG(printError,("Error in Controller input task\n",0,0,0,0,0,0));      
      }
      return CI857_ERROR;
  }
  
  RESULT CVenkyMsgQRead::OpenRead(void) {
  
      RESULT ret = CI857_OK;
  
      taskSpawn( "VenkyMsgQRead", 
          79, 
          0,
          4096,  /* stack size */
          ReadTask, 
          this, 2,3,4,5,6,7,8,9,10);
      return ret;
  }
  
  void CVenkyMsgQRead::TaskLoop(void)
  {
      STATUS MsgQStatus = OK;
  
      char msgBuf[MAX_MESSAGE_LENGTH];
      memset(msgBuf, 0x00, sizeof(msgBuf));
  
      while(1) {
  
          /* receive message */
          int msgLength = msgQReceive(msgQStudyId, msgBuf, MAX_MESSAGE_LENGTH,  WAIT_FOREVER) ;
          if(msgLength == ERROR) {
              printf("msgQReceive in taskTwo failed\n");  
          }
          else {
              printf(" Length received %d  and string is %s\n", msgLength, msgBuf); 
          }
           vosSleepMs( 5000 );
  
          memset(msgBuf, 0x00, sizeof(msgBuf));
      }
  }
  </code></pre>
  
  <p>Following is the output.</p>
  
  <p><code>enter code here</code>> msgQSend in CVenkyMsgQWrite::TaskLoop success msgQSend in</p>
  
  <blockquote>
    <p>CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success  Length received 7  and string is
    message msgQSend in CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success  Length received 7  and string is
    message msgQSend in CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success  Length received 7  and string is
    message msgQSend in CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success msgQSend in
    CVenkyMsgQWrite::TaskLoop success</p>
  </blockquote>
  
  <p>My question is</p>
  
  <ol>
  <li>As we are sending data fast then task is reading as we can have maximum of 100 messages of length 50  I am expecting 5 messages in the queue and lenght received to be 35. But that is not the case as we can see from above output we are reading length of 7 and of single message. </li>
  </ol>
  
  <p>Am I doing right? Is this expected behaviour? If I want to read length of 35 how should I read?</p>