Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could make a wrapper over <code>mq_send()</code> having char buffer allocated.</p> <p>Every message you send will be serialized into this buffer and then you will pass it to <code>mq_send</code> with appropriate length - sizeof(int) + sizeof(long) + strlen(pRecvData).</p> <p>The receiver will read this data and deserialize it into sFileStruct.</p> <p>IMHO using std::string instead of char* would be better.</p> <p>Sample code (not tested):</p> <pre><code>class MQWrapper { std::string m_strBuffer; public: int Send( const sFileStruct&amp; sfs ) { m_strBuffer.clear(); m_strBuffer.append( static_cast&lt;const char*&gt; &amp; sfs.uiCommand, sizeof(sfs.uiCommand) ); m_strBuffer.append( static_cast&lt;const char*&gt; &amp; sfs.ulNoOfBytes, sizeof(sfs.ulNoOfBytes) ); m_strBuffer.append( sfs.pRecvData ); // only if it's zero-terminated string!!! return mq_send(m_qSendDesc, m_strBuffer.c_str(), m_strBuffer.length(), inPriority); } char m_receiveBUffer[ BUFFER_SIZE ]; int Receive( sFileStruct&amp; sfs ) { int res = mq_receive( m_qSendDesc, receiveBUffer, BUFFER, outPriority ); if( res &lt; 0 ) return res; if( res &lt; sizeof(int) + sizeof(long) ) return -1000; // malformed message sfs.uiCommand = * ( static_cast&lt;unsigned int*&gt; (m_receiveBUffer[0]) ); sfs.ulNoOfBytes = * ( static_cast&lt;long*&gt; (m_receiveBUffer[ sizeof(int) ] ) ); // I don't really use this style in my work and not sure how to use it // str::string would be much easier int stringLen = res - sizeof(int) - sizeof(long); sfs.pRecvData = new char [ stringLen + 1 ]; // you have to delete [] it later if( stringLen &gt; 0 ) strcpy( sfs.pRecvData, receiveBUffer + sizeof(int) + sizeof(long), stringLen ); ss.pRecvData[ stringLen ] = '\0'; // null terminator return 0; } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload