private void Build(byte[] buffer)
 {
     _msg = new Received(new IPEndPoint(IPAddress.Any, 90), null, new BufferSlice(buffer, 0, buffer.Length, buffer.Length));
     if (_decoder == null)
     {
         _decoder = new MessageDecoder();
         _context = new MyCtx();
     }
 }
예제 #2
0
        private bool HandleReadBytes(int bytesRead)
        {
            try
            {
                if (bytesRead == 0)
                {
                    HandleDisconnect(null);
                    Dispose();
                    return false;
                }

                _readBuffer.Count += bytesRead;
                var lastOffset = -1;
                while (_readBuffer.RemainingLength != 0 && lastOffset != _readBuffer.Position)
                {
                    lastOffset = _readBuffer.Position;
                    var msg = new Received(_socket.RemoteEndPoint, _stream, _readBuffer);
                    SendUpstream(msg);
                }

                _logger.Debug(string.Format("Compacting since we got {1} bytes left from pos {0}.", _readBuffer.Position,
                                            _readBuffer.RemainingLength));
                _readBuffer.Compact();
                return true;
            }
            catch (Exception err)
            {
                Logger.Warning("A pipeline handler threw an exception.", err);
                Pipeline.SendUpstream(new PipelineFailure(err));

                Dispose();
                return false;
            }
        }