Example #1
0
        private void OnNewBytes(int size)
        {
            try
            {
                // Debug support
                if (Globals.TRACE_RECEIVE)
                {
                    Logger.ExceptionLogger.LogMessage("TRACE: ReceiveDataHandler.OnNewBytes() [" + topic.GetName() + "], got " + size + " bytes");
                }

                bytesReceived += size - headerBytes.Length;

                ReadByteBuffer readBuf = new ReadByteBuffer(headerBytes);

                if (readBuf.CheckProtocol())
                {
                    int nrOfFragments   = readBuf.ReadInt();
                    int currentFragment = readBuf.ReadInt();

                    if (currentFragment == (nrOfFragments - 1) && currentFragment == expectedFragment)
                    {
                        // We have received a full message, let's deserialize it and send
                        // it to subscribers.
                        SendBytesToSubscribers(new ReadByteBuffer(bytes));
                        expectedFragment = 0;
                        bytesReceived    = 0;
                    }
                    else
                    {
                        if (currentFragment == expectedFragment)
                        {
                            expectedFragment++;
                        }
                        else
                        {
                            // Not so good. Sample will be lost here.
                            if (Globals.REPORT_DATA_FRAGMENT_LOST_ERRORS)
                            {
                                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", Fragment error, sample lost");
                            }
                            expectedFragment = 0;
                            bytesReceived    = 0;
                        }
                    }
                }
            }
            catch (System.IO.IOException)
            {
                expectedFragment = 0;
            }
        }
Example #2
0
 ///
 /// <param name="name"></param>
 /// <param name="v"></param>
 public override int Inout(string name, int v)
 {
     return(readBuf.ReadInt());
 }