Beispiel #1
0
        void OnSessionDataReceived(object sender, DataEventArgs e)
        {
            var result = PipeLineProcessor.Process(new ArraySegment <byte>(e.Data, e.Offset, e.Length));

            if (result.State == ProcessState.Error)
            {
                m_Session.Close();
                return;
            }
            else if (result.State == ProcessState.Cached)
            {
                // allocate new receive buffer if the previous one was cached
                var session = m_Session;

                if (session != null)
                {
                    var bufferSetter = session as IBufferSetter;

                    if (bufferSetter != null)
                    {
                        bufferSetter.SetBuffer(new ArraySegment <byte>(new byte[session.ReceiveBufferSize]));
                    }
                }
            }

            if (result.Packages != null && result.Packages.Count > 0)
            {
                foreach (var item in result.Packages)
                {
                    HandlePackage(item);
                }
            }
        }
        private void OnSessionDataReceived(object sender, DataEventArgs e)
        {
            ProcessResult processResult;

            try
            {
                processResult = PipeLineProcessor.Process(new ArraySegment <byte>(e.Data, e.Offset, e.Length));
            }
            catch (Exception e2)
            {
                OnError(e2);
                m_Session.Close();
                return;
            }
            if (processResult.State == ProcessState.Error)
            {
                m_Session.Close();
                return;
            }
            if (processResult.State == ProcessState.Cached)
            {
                IClientSession session = m_Session;
                if (session != null)
                {
                    (session as IBufferSetter)?.SetBuffer(new ArraySegment <byte>(new byte[session.ReceiveBufferSize]));
                }
            }
            if (processResult.Packages != null && processResult.Packages.Count > 0)
            {
                foreach (IPackageInfo package in processResult.Packages)
                {
                    HandlePackage(package);
                }
            }
        }
 private void OnSessionClosed(object sender, EventArgs e)
 {
     m_Connected     = false;
     m_LocalEndPoint = null;
     PipeLineProcessor?.Reset();
     this.Closed?.Invoke(this, EventArgs.Empty);
     m_ConnectEvent.Set();
 }
Beispiel #4
0
        void m_Session_DataReceived(object sender, DataEventArgs e)
        {
            var result = PipeLineProcessor.Process(new ArraySegment <byte>(e.Data, e.Offset, e.Length), this as IBufferState);

            // allocate new receive buffer if the previous one was cached
            if (result.State == ProcessState.Cached)
            {
                var session = m_Session;

                if (session != null)
                {
                    var bufferSetter = session as IBufferSetter;

                    if (bufferSetter != null)
                    {
                        bufferSetter.SetBuffer(new ArraySegment <byte>(new byte[session.ReceiveBufferSize]));
                    }
                }
            }
        }