示例#1
0
        //public IAsyncAction OnData(byte[] data, int offset, int length) {
        public void OnData(byte[] data, int offset, int length)
        {
            //return Task.Run(async () =>
            //{
            try
            {
                while (_buffer.Length - _writeOffset < length)
                {
                    ExpandBuffer();
                }
                Array.Copy(data, offset, _buffer, _writeOffset, length);
                _writeOffset += length;

                SSH1Packet p = ConstructPacket();
                while (p != null)
                {
                    //await _handler.OnPacket(p);
                    _handler.OnPacket(p);
                    p = ConstructPacket();
                }
                ReduceBuffer();
            }
            catch (Exception ex)
            {
                OnError(ex, ex.Message);
            }
            //}).AsAsyncAction();
        }
        public void OnData(byte[] data, int offset, int length)
        {
            try {
                while (_buffer.Length - _writeOffset < length)
                {
                    ExpandBuffer();
                }
                Array.Copy(data, offset, _buffer, _writeOffset, length);
                _writeOffset += length;

                SSH1Packet p = ConstructPacket();
                while (p != null)
                {
                    _handler.OnPacket(p);
                    p = ConstructPacket();
                }
                ReduceBuffer();
            }
            catch (Exception ex) {
                OnError(ex, ex.Message);
            }
        }