示例#1
0
        private static Http2Connection.Http2Stream TryReuseStream(string scheme, string host, int port)
        {
            string key = scheme + "://" + host + ":" + port.ToString();

            Http2Connection.Http2Stream h2stream = null;

            RwLockedList <H2StreamInfo> streaminfo;

            if (m_H2StreamList.TryGetValue(key, out streaminfo))
            {
                lock (streaminfo)
                {
                    for (int i = 0; i < streaminfo.Count; ++i)
                    {
                        H2StreamInfo h2info = streaminfo[i];
                        if ((h2info.ValidUntil - Environment.TickCount) > 0 &&
                            h2info.Connection.AvailableStreams > 0)
                        {
                            h2info.ValidUntil = Environment.TickCount + 5000;
                            h2stream          = h2info.Connection.OpenClientStream();
                        }
                    }
                }
            }
            return(h2stream);
        }
示例#2
0
        private static void AddH2Connection(Http2Connection conn, string scheme, string host, int port)
        {
            string key    = scheme + "://" + host + ":" + port.ToString();
            var    h2info = new H2StreamInfo(conn, scheme, host, port);

            m_H2StreamList[key].Add(h2info);
            ThreadManager.CreateThread((o) =>
            {
                var info = (H2StreamInfo)o;
                System.Threading.Thread.CurrentThread.Name = "HTTP/2 client connection for " + key;
                try
                {
                    info.Connection.Run();
                }
                catch
                {
                    m_H2StreamList[key].Remove(info);
                }
            }).Start(h2info);
        }