private void HandlePingFrame(PingFrame pingFrame)
        {
            Http2Logger.LogDebug("Ping frame with StreamId:{0} Payload:{1}", pingFrame.StreamId,
                                             pingFrame.Payload.Count);

            if (pingFrame.FrameLength != PingFrame.PayloadLength)
            {
                throw new ProtocolError(ResetStatusCode.ProtocolError, "Ping payload size is not equal to 8");
            }

            if (pingFrame.IsPong)
            {
                _pingReceived.Set();
            }
            else
            {
                var pongFrame = new PingFrame(true, pingFrame.Payload.ToArray());
                _writeQueue.WriteFrame(pongFrame);
            }
        }
        /// <summary>
        /// Pings session.
        /// </summary>
        /// <returns></returns>
        public TimeSpan Ping()
        {
            var pingFrame = new PingFrame(false);
            _writeQueue.WriteFrame(pingFrame);
            var now = DateTime.UtcNow;

            if (!_pingReceived.WaitOne(3000))
            {
                //Remote endpoint was not answer at time.
                Dispose();
            }
            _pingReceived.Reset();

            var newNow = DateTime.UtcNow;
            Http2Logger.LogDebug("Ping: " + (newNow - now).Milliseconds);
            return newNow - now;
        }
        private void HandlePingFrame(PingFrame pingFrame)
        {
            //09 -> 6.7.  PING
            //PING frames are not associated with any individual stream.  If a PING
            //frame is received with a stream identifier field value other than
            //0x0, the recipient MUST respond with a connection error
            //(Section 5.4.1) of type PROTOCOL_ERROR.

            if (pingFrame.StreamId != 0)
            {
                throw new ProtocolError(ResetStatusCode.ProtocolError,
                                        "Incoming ping frame with id != 0");
            }

            Http2Logger.LogDebug("Ping frame with StreamId:{0} Payload:{1}", pingFrame.StreamId,
                                             pingFrame.Payload.Count);

            if (pingFrame.FrameLength != PingFrame.PayloadLength)
            {
                throw new ProtocolError(ResetStatusCode.ProtocolError, "Ping payload size is not equal to 8");
            }

            if (pingFrame.IsAck)
            {
                _pingReceived.Set();
            }
            else
            {
                var pingAckFrame = new PingFrame(true, pingFrame.Payload.ToArray());
                _writeQueue.WriteFrame(pingAckFrame);
            }
        }