Ejemplo n.º 1
0
        /// <summary>
        /// Processes the messages.
        /// </summary>
        /// <param name="stateInfo">The state info.</param>
        private void ProcessMessages(Object stateInfo)
        {
            do
            {
                byte[] data = ReceiveData();

                SocketEventArgs args = new SocketEventArgs(data);
                OnSocketData(this, args);
            }while (this.opened);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler for Http2 data.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">Event arguments.</param>
        private void OnSocketData(object sender, SocketEventArgs e)
        {
            try
            {
                BaseFrame frame = this.serializer.Deserialize(e.BinaryData);

                if (this.OnFrameReceived != null)
                {
                    this.OnFrameReceived(this, new FrameEventArgs(frame));
                }
                try
                {
                    if (frame is DataFrame)
                    {
                        this.ProcessDataFrame((DataFrame)frame);
                    }
                    else if (frame is ControlFrame)
                    {
                        this.ProcessControlFrame((ControlFrame)frame);
                    }
                    else
                    {
                        throw new InvalidOperationException("Unsupported frame type");
                    }
                }
                catch (Exception streamError)
                {
                    if (streamError is ProtocolExeption || this.OnStreamError == null)
                    {
                        throw;
                    }

                    this.OnStreamError(this, new StreamErrorEventArgs(this.streamsStore.GetStreamById(frame.StreamId), streamError));
                }
            }
            catch (Exception protocolError)
            {
                if (this.OnError != null)
                {
                    this.OnError(this, new ProtocolErrorEventArgs(protocolError));
                }
            }
        }