int ReceiveMessage ()

ConcurrencyrsSequentialConcurrencyVisibilityrsProtected

Code
int nRead;
if (nSizeRemaining)
{
    // Each message starts with an unsigned long that is the number of bytes
    // in the body of the message.
    nRead = c_socket.read(readBuffer + sizeof(unsigned long) - nSizeRemaining,
        nSizeRemaining);
    if(nRead <= 0)
        return IPCReturn(0, false);    // read not finished, no reset

    nSizeRemaining -= nRead;
    if (nSizeRemaining == 0)
    {
        // Read of unsigned long complete
        RTMemoryUtil::memcpy(&nNums, readBuffer, sizeof(unsigned long));
        if(nNums > TS_MAXNUMS)
        {
            // This is either an internal error or a TCP/IP failure.
            // Shutdown the test, log an error and stop polling for messages.
            AddIn.Reset().send();
            RQART_Log.log("RQARTTCPServer detected an error. Please cancel the test.");
            return IPCReturn(0, false, false); // failed, no reset, no timeout
        }
        nBodyRemaining = TS_MESSAGE_SIZE(nNums);
        nSize = nBodyRemaining;
    }
}

if (nBodyRemaining != -1)
{
    // Read the message body
    nRead = c_socket.read(readBuffer + nSize - nBodyRemaining, nBodyRemaining);
    if(nRead <= 0)
        return IPCReturn(0, false);

    nBodyRemaining -= nRead;
    if (nBodyRemaining == 0)
    {
        // Read of message complete
        anBuffer[0] = readBuffer[0];
        for(int i=1; i <= nNums ; i++)
        {
            unsigned long start = (i-1) * sizeof(unsigned long) + 1;
            unsigned long wData;
            RTMemoryUtil::memcpy(&wData, readBuffer + start, sizeof(unsigned long));
            anBuffer[i] = wData;
        }
        return IPCReturn(1, true);    // read finished, reset
    }
}
return IPCReturn(0, false);    // read not finished, no reset