Ejemplo n.º 1
0
        private void _buffer_Receive(object sender, SegmentMessage <TSender> e)
        {
            bool          newUser = false;
            MessageBuffer buff;

            lock (this._buffers)
            {
                if (!this._buffers.TryGetValue(e.Sender, out buff))
                {
                    if (e.Data.Count > 0)
                    {
                        return;
                    }
                    newUser = true;
                    if (!e.IsOwnMessage)
                    {
                        this._newUsers = true;
                    }
                    this._buffers.Add(e.Sender, buff = new MessageBuffer());
                }
            }

            if (newUser)
            {
                this.DiscoverSender?.Invoke(this, e.Sender);
            }

            lock (buff)
            {
                if (e.Data.Count == 0)
                {
                    buff.Reset();
                    return;
                }

                for (var i = e.Data.Offset; i < e.Data.Offset + e.Data.Count; i++)
                {
                    buff.AddByte(e.Data.Array[i]);

                    var bytes = buff.CheckForMessages();
                    if (bytes != null)
                    {
                        this.Receive?.Invoke(this, new Message <TSender>(e.Sender, e.IsOwnMessage, bytes));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void _padder_Receive(object sender, SegmentMessage <TSender> e)
        {
            if (e.IsOwnMessage)
            {
                this._timeoutResetEvent.Set();

                this.ResendMissed(e.Data);
                this.FlushBuffer();
            }

            if (e.Data.Count == 0)
            {
                return;
            }
            var location = (byte)(e.Data.Array[e.Data.Offset] - Config.CounterOffset);
            var data     = ByteHelper.CropArray(e.Data, 1);

            this.Receive?.Invoke(this,
                                 new OrderedMessage <TSender>(
                                     e.Sender, e.IsOwnMessage,
                                     location, data));
        }